Results 1 to 2 of 2
  1. #1
    badness is offline Member
    Join Date
    Nov 2007
    Posts
    8
    Rep Power
    0

    Default Inventory part 2 help please

    Hey there. I am new to Java and I have an assignment that I could use some help with, if you please.

    Program requirements are as follows:

    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 is my code: I am having trouble with line 100 please advise. Thanks.

    public class Inventory2 {

    public static void main(String args []) {

    DVD dvd;


    dvd = new DVD(1, "The Fellowship of the Ring", 5, 14.95);
    System.out.println(dvd);

    dvd = new DVD(2, "The Chamber", 7, 12.99);
    System.out.println(dvd);

    dvd = new DVD(3, "Superman 3", 6, 19.99);
    System.out.println(dvd);

    dvd = new DVD(4, "Van Helsing", 3, 10.99);
    System.out.println(dvd);

    } //end main

    } // end class Inventory2


    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(String 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(double 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

    class Inventory {
    DVD movies[] = new DVD[100];

    // Add to inventory
    public void addToInventory(DVD movie) {


    }

    // Get inventory value
    public double getInventoryValue() {
    return inventory;

    Inventory myInventory = new Inventory();


    myInventory.addToInventory(new DVD(1, "Remember the Titans", 5, 14.95));

    // Print out the inventory total value
    System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());

    }
    }

    Again, thanks for any help I might receive.

    Badness

  2. #2
    revathi17 is offline Member
    Join Date
    Aug 2007
    Posts
    26
    Rep Power
    0

    Default

    From what you have posted, there is a problem in the Inventory class, you have to change the return and put it at the end, like this:
    Java Code:
    ....
    class Inventory {
    	DVD movies[] = new DVD[100];
    
    	// Add to inventory
    	public void addToInventory(DVD movie) {
    	}
    
    	// Get inventory value
    	public double getInventoryValue() {
    		Inventory myInventory = new Inventory();
    		myInventory.addToInventory(new DVD(1, "Remember the Titans", 5, 14.95));
    		// Print out the inventory total value
    		System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());
    		return myInventory.getInventoryValue();
    	}
    }
    I didn't go through the logic, but from the code you had written , I assumed this is what you wanted to do..

    Hope this helps,
    -R

Similar Threads

  1. Final Inventory tweeks
    By badness in forum New To Java
    Replies: 1
    Last Post: 01-20-2008, 08:18 AM
  2. Inventory Program modification help
    By badness in forum Java Applets
    Replies: 1
    Last Post: 01-17-2008, 05:24 AM
  3. How to get part of a String?
    By eva in forum New To Java
    Replies: 1
    Last Post: 12-23-2007, 06:58 AM
  4. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 07:00 AM
  5. Inventory program
    By Nexcompac in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •