http://faculty.unlv....assignment6.doc
Now, I have completed it, but I am not sure if I did it the right way, and I know that it could probably be simplified. Any help would be great. Thanks
Here is my code:
import java.text.DecimalFormat;
public class Client
{
public static void main(String[] args)
{
//Set Product Information
//Product Number, Name, Price
Product com = new Product(1, "Computer", 350.00);
Product pri = new Product(2, "Printer", 40.00);
Product sca = new Product(3, "Scanner", 45.50);
Product dig = new Product(4, "Digital Camera", 150.99);
//Set Order Information
//Order Number, Date
Order one = new Order(1, "October 10, 2007");
Order two = new Order(2, "October 23, 2007");
//Set Lineitem Information
//Lineitem Number, Quantity
Lineitem first = new Lineitem(1, 1); //1 Computer
Lineitem second = new Lineitem(2, 2); //2 Printers
Lineitem third = new Lineitem(3, 1); //1 Computer
Lineitem fourth = new Lineitem(4, 3); //3 Scanners
Lineitem fifth = new Lineitem(5, 2); //2 Cameras
//decimal format
DecimalFormat bal = new DecimalFormat ("$#,##0.00");
//Extra Credit Table Structure
String order1 = "Order # " + one.getOrderNumber();
String order2 = "Order # " + two.getOrderNumber();
String header = "Lineitem # Product Price Quantity Total";
String table1 = " " + first.getItemNum() + " " + com.getProdname() + " " +
bal.format(com.getProdprice()) + " " + first.getQuantity() + " " +
bal.format(com.getProdprice() * first.getQuantity());
String table2 = " " + second.getItemNum() + " " + pri.getProdname() + " " +
bal.format(pri.getProdprice()) + " " + second.getQuantity() + " " +
bal.format(pri.getProdprice() * second.getQuantity());
String table3 = " " + third.getItemNum() + " " + com.getProdname() + " " +
bal.format(com.getProdprice()) + " " + third.getQuantity() + " " +
bal.format(com.getProdprice() * third.getQuantity());
String table4 = " " + fourth.getItemNum() + " " + sca.getProdname() + " " +
bal.format(sca.getProdprice()) + " " + fourth.getQuantity() + " " +
bal.format(sca.getProdprice() * fourth.getQuantity());
String table5 = " " + fifth.getItemNum() + " " + dig.getProdname() + " " +
bal.format(dig.getProdprice()) + " " + fifth.getQuantity() + " " +
bal.format(dig.getProdprice() * fifth.getQuantity());
String total1 = "Grand total: " + bal.format((com.getProdprice() * first.getQuantity()) +
(pri.getProdprice() * second.getQuantity()));
String total2 = "Grand total: " + bal.format((com.getProdprice() * third.getQuantity()) +
(sca.getProdprice() * fourth.getQuantity()) + (dig.getProdprice() * fifth.getQuantity()));
System.out.println(order1);
System.out.println(header);
System.out.println(table1);
System.out.println(table2);
System.out.println(total1);
System.out.println("\n" + order2);
System.out.println(header);
System.out.println(table3);
System.out.println(table4);
System.out.println(table5);
System.out.println(total2);
}
}
public class Product
{
private int prodnum; //product number
private String prodname; //product name
private double prodprice; //unit price
//Product variables
Product (int x, String y, double z)
{
prodnum = x;
prodname = y;
prodprice = z;
}
public int getProdnum()
{
return prodnum;
}
public String getProdname()
{
return prodname;
}
public double getProdprice()
{
return prodprice;
}
public void setProdnum(int x)
{
prodnum = x;
}
public void setProdname(String y)
{
prodname = y;
}
public void setProdprice(double z)
{
prodprice = z;
}
}
public class Order
{
private int orderNumber; //Order Number
private String orderDate; //Order Date stored as a String variable
//Order variables
Order(int x, String y)
{
orderNumber = x;
orderDate = y;
}
public int getOrderNumber()
{
return orderNumber;
}
public String getOrderDate()
{
return orderDate;
}
public void setOrderNumber(int x)
{
orderNumber = x;
}
public void setOrderDate(String y)
{
orderDate = y;
}
}
public class Lineitem
{
private int itemNum; //Item number
private int quantity; //Item quantity
private Product lineProduct;
//Lineitem variables
Lineitem(int x, int y)
{
itemNum = x;
quantity = y;
}
public int getItemNum()
{
return itemNum;
}
public int getQuantity()
{
return quantity;
}
public void setItemNum(int x)
{
itemNum = x;
}
public void setQuantity(int y)
{
quantity = y;
}
}

New Topic/Question
Reply




MultiQuote




|