Problem in Program


HELLO,

i HAVE AN ASSIGHNMENT THAT HAS ME PUZZLED > I CAN GET TOTALS ON INVENTORY ITEMS SEPERATLY , BUT CANT GET GRAND TOTAL I AM HONEST WITH MY TEACHEER MRS. FERIBEE AT AXIA AND SHE TOLD ME I COULD LEARN A GREAT DEAL FROM FORUMS SO HERE I AM. THIS WAS SUPPOSED TO BE DONE IN ARRAYS BUT i HAD TWO MANY ERRORs SO i WILL USE THIS ONE. How do I get total inventory. I have another programI done in arrays I am trying to finish.


public class Inventory{

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
class Product {

private int itemNumber;
private String name;
private int unitsInStock;
private double unitPrice;

public Product(int itemNumber, String name, int unitsInStock,
double unitPrice) {
this.itemNumber = itemNumber;
this.name = name;
this.unitsInStock = unitsInStock;
this.unitPrice = unitPrice;
}

public double getValueOfProduct() {
return unitsInStock * unitPrice;
}


public String toString() {
String itemStr = "Item: " + String.format("%-3s | ", itemNumber);
String titleStr = "Name: " + String.format("%-10s | ", name);
String unitsStr = "Units: " + String.format("%4d | ", unitsInStock);
String costStr = "Unit: " + String.format("$ %6.2f | ", unitPrice);
String valueStr = "Value: "
+ String.format("$ %8.2f", getValueOfProduct());

return itemStr + titleStr + unitsStr + costStr + valueStr;
}

}

{

{

Product one = new Product(1, "Polaris90", 2, 1000.00);
Product two = new Product(2, "Polaris125", 3, 1250.50);
Product three = new Product(3, "POLARIS250", 1, 2999.00);
Product four = new Product(4, "YAMAHA90", 2, 1199.99);
Product five = new Product(5, "Yamaha110", 5, 1299.00);
Product six = new Product(6, "Suzuki50", 7, 812.50);



System.out.println(one);
System.out.println(two);
System.out.println(three);
System.out.println(four);
System.out.println(five);
System.out.println(six);


}

}
}

}
THIS IS MY PRINT OUT BUT NEED TOTAL
Item: 1 | Name: Polaris90 | Units: 2 | Unit: $ 1000.00 | Value: $ 2000.00
Item: 2 | Name: Polaris125 | Units: 3 | Unit: $ 1250.50 | Value: $ 3751.50
Item: 3 | Name: POLARIS250 | Units: 1 | Unit: $ 2999.00 | Value: $ 2999.00
Item: 4 | Name: YAMAHA90 | Units: 2 | Unit: $ 1199.99 | Value: $ 2399.98
Item: 5 | Name: Yamaha110 | Units: 5 | Unit: $ 1299.00 | Value: $ 6495.00
Item: 6 | Name: Suzuki50 | Units: 7 | Unit: $ 812.50 | Value: $ 5687.50
Posted On: Thursday 25th of October 2012 01:51:46 AM Total Views:  107
View Complete with Replies

RELATED TOPICS OF Java PROGRAMMING LANGUAGE