Hello,
I am supposed to modify my last inventory program. Here is the instructions. Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
Create a method to calculate the value of the entire inventory.
Create another method to sort the array items by the name of the product.
I feel completely lost as this is an online class and I have no one to ask for help. I have a hard time learning from readings.
Here is my code so far, if anyone can help me it would be so great cause I am stuck.
/* Public class: Inventory1.java
* Program displays inventory.
*/
/** Inventory1.java
* Author Melissa
* IT215 Java
* 10/29/2014
*/
class Pizza {
private Integer itemNumber;// Item number
private String productName;// Product name
private Integer productInStock;// Number of product in stock
private double productPrice;// Price per product
// Consturctor
public Pizza( Integer inlItemNumber, String inlProductName, Integer inlProductInStock, double inlProductPrice)
{
// accepts four parameters
setItemNumber(inlItemNumber);
setProductName(inlProductName);
setProductInStock(inlProductInStock);
setProductPrice(inlProductPrice);
}//End constructor
public Integer getItemNumber(){
return this.itemNumber;
}
public void setItemNumber(Integer inlItemNumber){
this.itemNumber = inlItemNumber;
}
public String getProductName(){
return this.productName;
}
public void setProductName(String inlProductName){
this.productName = inlProductName;
}
public Integer getProductInStock(){
return this.productInStock;
}
public void setProductInStock(Integer inlProductInStock){
this.productInStock = inlProductInStock;
}
public double getProductPrice(){
return this.productPrice;
}
public void setProductPrice(double inlProductPrice){
this.productPrice = inlProductPrice;
}//end
// Calculation methods
public double CalculateTotalProductValue () // begin calculateTotalProductValue method
{
return getProductInStock() * getProductPrice();
} // end calculateTotalProductValue method
public double CalculateTotalInventoryValue()
{
return CalculateTotalProductValue() * getProductInStock();
}
} // end Pizza class
public class Inventory1 {
public static void main(String[] args)
{
//instantiate Pizza array
Pizza myPizza[] = new Pizza[5];
myPizza[0] = new Pizza (1234, "Dough", 22, 1.59);
myPizza[1] = new Pizza (1235, "Sauce", 35, 5.99);
myPizza[2] = new Pizza (1236, "Cheese", 4, 15.99);
myPizza[3] = new Pizza (1237, "Pepperoni", 3, 14.99);
myPizza[4] = new Pizza (1238, "Ham", 2, 16.99);
//output
for (Pizza myPizza1 : myPizza) {
System.out.println(" The product Number: " + myPizza1.getItemNumber());
System.out.println(" The product Name: " + myPizza1.getProductName());
System.out.println(" The number of product in Stock: " + myPizza1.getProductInStock());
System.out.printf(" The price per product is: ", +myPizza1.getProductPrice());
System.out.printf(" The total product value is: ", +myPizza1.CalculateTotalProductValue());
}
//output total inventory value
double total = 0.0;
for (int i = 0; i < 5; i++){
total += myPizza[i].CalculateTotalInventoryValue();
}
System.out.printf("Total Value of Inventory is: ", total);
} // end main method
}//end inventory class
This is the output which is not desired:
The product Number: 1234
The product Name: Dough
The number of product in Stock: 22
The price per product is: The total product value is: The total inventory value is: 0.0
Item number is 1234
The product name is Dough
The number of products in stock are: 22
The price of each product is: $1.59
The product inventory value is: $34.98
The Total inventory value is: $0.00
The product Number: 1235
The product Name: Sauce
The number of product in Stock: 35
The price per product is: The total product value is: The total inventory value is: 0.0
Item number is 1235
The product name is Sauce
The number of products in stock are: 35
The price of each product is: $5.99
The product inventory value is: $209.65
The Total inventory value is: $0.00
The product Number: 1236
The product Name: Cheese
The number of product in Stock: 4
The price per product is: The total product value is: The total inventory value is: 0.0
Item number is 1236
The product name is Cheese
The number of products in stock are: 4
The price of each product is: $15.99
The product inventory value is: $63.96
The Total inventory value is: $0.00
The product Number: 1237
The product Name: Pepperoni
The number of product in Stock: 3
The price per product is: The total product value is: The total inventory value is: 0.0
Item number is 1237
The product name is Pepperoni
The number of products in stock are: 3
The price of each product is: $14.99
The product inventory value is: $44.97
The Total inventory value is: $0.00
The product Number: 1238
The product Name: Ham
The number of product in Stock: 2
The price per product is: The total product value is: The total inventory value is: 0.0
Item number is 1238
The product name is Ham
The number of products in stock are: 2
The price of each product is: $16.99
The product inventory value is: $33.98
The Total inventory value is: $0.00
BUILD SUCCESSFUL (total time: 0 seconds)