here's what i have to do:
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.
here's my code that i have so far...
public class Inventory1 {
public static void main(String[] args) {
DVD dvd;
dvd = new DVD(1, "Frosty The Snowman", 5, 14.95);
System.out.prin tln(dvd);
dvd = new DVD(2, "Charlie Brown Christmas", 7, 12.99);
System.out.prin tln(dvd);
dvd = new DVD(3, "Rudolph The Red-Nosed Reindeer", 6, 19.99);
System.out.prin tln(dvd);
dvd = new DVD(4, "The Grinch Who Stole Christmas",3, 10.99);
System.out.prin tln(dvd);
} //end main
} // end class Inventory1
class DVD {
private int dvdItem;
private String dvdTitle;
private int dvdStock;
private double dvdPrice;
public DVD(int item, String title, int stock, double price) {
dvdItem = item;
dvdTitle = title;
dvdStock = stock;
dvdPrice = price;
} //end four-argument constructor
// set DVD Item
public void setDvdItem(int item) {
dvdItem = item;
} //end method set Dvd Item
//return DVD Item
public int getDvdItem() {
return dvdItem;
} //end method get Dvd Item
//set DVD Title
public void setDvdTitle(Str ing title) {
dvdTitle = title;
} //end method set Dvd Title
//return Dvd Title
public String getDvdTitle() {
return dvdTitle;
} //end method get Dvd Title
public void setDvdStock(int stock) {
dvdStock = stock;
} //end method set Dvd Stock
//return dvd Stock
public int getDvdStock() {
return dvdStock;
} //end method get Dvd Stock
public void setDvdPrice(dou ble price) {
dvdPrice = price;
} //end method setdvdPrice
//return DVD Price
public double getDvdPrice() {
return dvdPrice;
} //end method get Dvd Price
//calculate inventory value
public double value() {
return dvdPrice * dvdStock;
} //end method value
public String toString() {
return String.format(" item=%3d title=%-20s units=%d price=%.2f value=%.2f",
dvdItem, dvdTitle, dvdStock, dvdPrice, value());
}
} //end class DVD
any help would be appreciated....
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.
here's my code that i have so far...
public class Inventory1 {
public static void main(String[] args) {
DVD dvd;
dvd = new DVD(1, "Frosty The Snowman", 5, 14.95);
System.out.prin tln(dvd);
dvd = new DVD(2, "Charlie Brown Christmas", 7, 12.99);
System.out.prin tln(dvd);
dvd = new DVD(3, "Rudolph The Red-Nosed Reindeer", 6, 19.99);
System.out.prin tln(dvd);
dvd = new DVD(4, "The Grinch Who Stole Christmas",3, 10.99);
System.out.prin tln(dvd);
} //end main
} // end class Inventory1
class DVD {
private int dvdItem;
private String dvdTitle;
private int dvdStock;
private double dvdPrice;
public DVD(int item, String title, int stock, double price) {
dvdItem = item;
dvdTitle = title;
dvdStock = stock;
dvdPrice = price;
} //end four-argument constructor
// set DVD Item
public void setDvdItem(int item) {
dvdItem = item;
} //end method set Dvd Item
//return DVD Item
public int getDvdItem() {
return dvdItem;
} //end method get Dvd Item
//set DVD Title
public void setDvdTitle(Str ing title) {
dvdTitle = title;
} //end method set Dvd Title
//return Dvd Title
public String getDvdTitle() {
return dvdTitle;
} //end method get Dvd Title
public void setDvdStock(int stock) {
dvdStock = stock;
} //end method set Dvd Stock
//return dvd Stock
public int getDvdStock() {
return dvdStock;
} //end method get Dvd Stock
public void setDvdPrice(dou ble price) {
dvdPrice = price;
} //end method setdvdPrice
//return DVD Price
public double getDvdPrice() {
return dvdPrice;
} //end method get Dvd Price
//calculate inventory value
public double value() {
return dvdPrice * dvdStock;
} //end method value
public String toString() {
return String.format(" item=%3d title=%-20s units=%d price=%.2f value=%.2f",
dvdItem, dvdTitle, dvdStock, dvdPrice, value());
}
} //end class DVD
any help would be appreciated....
Comment