My assignment says: 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 truely do not know if I am re-writing all my program or I am just adding to it? And either way I do not know know where to start. Here is what I have:

package javaapplication25;

    public class FGInventoryProgram1{  
        FGInventoryProgram1() {    // constructor  
           DVD[] dvd =  new DVD[4];  
            dvd[0] = new DVD("How to Loose a Guy in 10 days", 4, 19.99, 685.0);  
           dvd[1] = new DVD("Cyote Ugly", 8, 19.98, 565.0);  
            dvd[2] = new DVD("Legally Blonde", 10, 19.99,785.0);  
           dvd[3] = new DVD("Sweet Home Alabama",8,18.56,578.0);           for(int i = 0; i < 4; i++) {  
               System.out.println("Product Title is " + dvd[i].getDvdTitle());  
               System.out.println("The number of units in stock is" + dvd[i].getDvdStock());  
               System.out.println("The price of each DVD is" + dvd[i].getDvdPrice());  
               System.out.println("The item number is " + dvd[i].getDvdItem());  
               System.out.println("The value of the inventory is" + dvd[i].value());  
       public static void main(String args []) {  
           new FGInventoryProgram1();  
       } //end method main  
       class DVD {  
           private String dvdTitle;  
           private double dvdStock;  
           private double dvdPrice;  
           private double dvdItem;  
           DVD(String title, double stock, double price, double item) {  
               dvdTitle = title;  
               dvdStock = stock;  
               dvdPrice = price;  
               dvdItem  = item;  
           } //end four-argument constructor  
           public void setDvdTitle(String title) {  
               dvdTitle = title;  
           } //end method  setDvdTitle  
           //return DVD Title  
           public String getDvdTitle() {  
               return dvdTitle;  
           } //end method getDvdTitle  
           //set DVD Stock  
           public void setDvdStock(double stock) {  
               dvdStock = stock;  
           } //end method setDvdStock  
           //return DvdStock  
           public double getDvdStock() {  
               return dvdStock;  
           } //end method get Dvdstock  
           public void setDvdPrice(double price) {  
               dvdPrice = price;  
           } //end method setDvdPrice  
           //return dvdPrice  
           public double getDvdPrice() {  
               return dvdPrice;  
           } //end method get Dvd Price  
           public void setDvdItem(double item) {  
               dvdItem = item;  
           } //end method setdvdItem  
           //return DVD item  
           public double getDvdItem() {  
               return dvdItem;  
           } //end  method getDvdItem  
           //calculate inventory value  
           public double value() {  
               return dvdPrice * dvdStock;  
           } //end method value  
       } //end class DVD  
8 Years
Discussion Span
Last Post by javaAddict

Create a method to calculate the value of the entire inventory.

It is the classic algorithm: sum += sum+VALUE. Write a method the takes as argument the array of DVDs and inside a for loop calculate the sum. As VALUE you should use:

Create another method to sort the array items by the name of the product

Create a method that takes as argument an array of DVD and returns another array of DVD.
Surely you must know some basic sorting algorithms. Use the value: dvd.getDvdTitle() to sort the array, but don't forget that you will need to put the entire object in the new array not just the dvd.getDvdTitle()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.