Closed Thread
Results 1 to 7 of 7

Thread: Need Java help ASAP : (

  1. #1
    kris1976 is offline Newbie
    Join Date
    May 2009
    Posts
    14
    Rep Power
    0

    Need Java help ASAP : (

    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.
    Post as an attachment in java format.
    I am getting error that identifier is needed at lines 87 and 90, I marked them in red... also not sure if the Class inventory is correct so it will sort... please help!! Thanks so much!!

    Code:
    public class InventoryProgramPart2 {
    
    public static void main(String args []) {
    
    CD cd;
    
    cd = new CD(1, "Elton John", 9, 15.00);
    System.out.println(cd);
    
    cd = new CD(2, "Beyonce", 2, 13.99);
    System.out.println(cd);
    
    cd = new CD(3, "George Straight", 5, 14.00);
    System.out.println(cd);
    
    cd = new CD(4, "Tim McGraw", 4, 12.99);
    System.out.println(cd);
    
    } // end main
    
    } // end class InventoryProgramPart2
    
    class CD {
    private int cdItem;
    private String cdArtist;
    private int cdStock;
    private double cdPrice;
    
    public CD(int item, String artist, int stock, double price) {
    	cdItem = item;
    	cdArtist = artist;
    	cdStock = stock;
    	cdPrice = price;
    } //end constructor
    
    //set CD Item
    public void setCdItem(int item) {
    	cdItem = item;
    } //end method set Cd Item
    
    //return CD Item
    public int getCdItem() {
    	return cdItem;
    } //end method get Cd Item
    
    //set CD Artist
    public void setCdArtist(String artist) {
    	cdArtist = artist;
    } //end method set Cd Artist
    
    //return Cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } //end method get Cd Artist
    
    public void setCdStock(int stock) {
    	cdStock = stock;
    } //end method set Cd Stock
    
    //return cd Stock
    public int getCdStock() {
    return cdStock;
    } //end method get Cd Stock
    
    public void setCdPrice(double price) {
    	cdPrice = price;
    } //end method set Cd Price
    
    //return Cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    //calculate inventory value
    public double value() {
    	return cdPrice * cdStock;
    } // end method inventory value
    
    public String toString() {
    
    return String.format("item=%3d, artist=%-20s, units=%d, price=%.2f, value=%.2f", cdItem, cdArtist, cdStock, cdPrice, value());
    }
    
    } //end class CD
    
    class Inventory {
    	CD[] = new CD[100];
    
    // Add to inventory
    public static void addToInventory(CD) {
    }
    
    // Get inventory value
    public double getInventoryValue() {
    	Inventory myInventory = new Inventory ();
    	myInventory.addToInventory(new CD(5, "Poison", 3, 11.99));
    
    // Print Total Inventory
    System.out.println("Total inventory value is: " + myInventory.getInventoryValue());
    return myInventory.getInventoryValue();
    }
    }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Need Java help ASAP : (

    Moved to correct forum.

  4. #3
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Need Java help ASAP : (

    Code:
    CD[] = new CD[100];
    You haven't given a name to the array.

    Change to:

    Code:
    CD[] arOCD = new CD[100];
    The term between CD[] and = is the name of the array. That is why you forgot.

  5. #4
    kris1976 is offline Newbie
    Join Date
    May 2009
    Posts
    14
    Rep Power
    0

    Re: Need Java help ASAP : (

    thank you so much, but now it is telling me identifier is expected on line 91 which I highlighted in red. ??? I'm not sure how to fix that.. any help would be greatly appreciated.
    Code:
    public class InventoryProgramPart2 {
    
    public static void main(String args []) {
    
    CD cd;
    
    cd = new CD(1, "Elton John", 9, 15.00);
    System.out.println(cd);
    
    cd = new CD(2, "Beyonce", 2, 13.99);
    System.out.println(cd);
    
    cd = new CD(3, "George Straight", 5, 14.00);
    System.out.println(cd);
    
    cd = new CD(4, "Tim McGraw", 4, 12.99);
    System.out.println(cd);
    
    } // end main
    
    } // end class InventoryProgramPart2
    
    class CD {
    private int cdItem;
    private String cdArtist;
    private int cdStock;
    private double cdPrice;
    
    public CD(int item, String artist, int stock, double price) {
    	cdItem = item;
    	cdArtist = artist;
    	cdStock = stock;
    	cdPrice = price;
    } //end constructor
    
    //set CD Item
    public void setCdItem(int item) {
    	cdItem = item;
    } //end method set Cd Item
    
    //return CD Item
    public int getCdItem() {
    	return cdItem;
    } //end method get Cd Item
    
    //set CD Artist
    public void setCdArtist(String artist) {
    	cdArtist = artist;
    } //end method set Cd Artist
    
    //return Cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } //end method get Cd Artist
    
    public void setCdStock(int stock) {
    	cdStock = stock;
    } //end method set Cd Stock
    
    //return cd Stock
    public int getCdStock() {
    return cdStock;
    } //end method get Cd Stock
    
    public void setCdPrice(double price) {
    	cdPrice = price;
    } //end method set Cd Price
    
    //return Cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    //calculate inventory value
    public double value() {
    	return cdPrice * cdStock;
    } // end method inventory value
    
    public String toString() {
    
    return String.format("item=%3d, artist=%-20s, units=%d, price=%.2f, value=%.2f", cdItem, cdArtist, cdStock, cdPrice, value());
    }
    
    } //end class CD
    
    class Inventory{
    
    	CD[]arOCD = new CD[50];
    
    // Add to inventory
    public void addToInventory(CD) {
    }
    // Get inventory value
    public double getInventoryValue() {
    	Inventory myInventory = new Inventory();
    	myInventory.addToInventory(new CD(5, "Poison", 3, 11.99));
    
    // Print total value of inventory
    	System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());
    		return myInventory.getInventoryValue();}
    }

  6. #5
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Need Java help ASAP : (

    Code:
    public void addToInventory(CD)
    In the parenthesize you have to give a name to the parameter.

    Code:
    public void addToInventory(CD cd1) {
    
    }
    When you declare a variable you have to give it a type and a name.

  7. #6
    kris1976 is offline Newbie
    Join Date
    May 2009
    Posts
    14
    Rep Power
    0

    Re: Need Java help ASAP : (

    Wow that worked, thank you again! Only problem now is that it didn't add in the new CD (Poison) and it didn't display the total Inventory for all the CD's (but there are no errors)?? I really appreciate your help, I have 3 more weeks of this class and it has become so difficult.
    Code:
    public class InventoryProgramPart2 {
    
    public static void main(String args []) {
    
    CD cd;
    
    cd = new CD(1, "Elton John", 9, 15.00);
    System.out.println(cd);
    
    cd = new CD(2, "Beyonce", 2, 13.99);
    System.out.println(cd);
    
    cd = new CD(3, "George Straight", 5, 14.00);
    System.out.println(cd);
    
    cd = new CD(4, "Tim McGraw", 4, 12.99);
    System.out.println(cd);
    
    } // end main
    
    } // end class InventoryProgramPart2
    
    class CD {
    private int cdItem;
    private String cdArtist;
    private int cdStock;
    private double cdPrice;
    
    public CD(int item, String artist, int stock, double price) {
    	cdItem = item;
    	cdArtist = artist;
    	cdStock = stock;
    	cdPrice = price;
    } //end constructor
    
    //set CD Item
    public void setCdItem(int item) {
    	cdItem = item;
    } //end method set Cd Item
    
    //return CD Item
    public int getCdItem() {
    	return cdItem;
    } //end method get Cd Item
    
    //set CD Artist
    public void setCdArtist(String artist) {
    	cdArtist = artist;
    } //end method set Cd Artist
    
    //return Cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } //end method get Cd Artist
    
    public void setCdStock(int stock) {
    	cdStock = stock;
    } //end method set Cd Stock
    
    //return cd Stock
    public int getCdStock() {
    return cdStock;
    } //end method get Cd Stock
    
    public void setCdPrice(double price) {
    	cdPrice = price;
    } //end method set Cd Price
    
    //return Cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    //calculate inventory value
    public double value() {
    	return cdPrice * cdStock;
    } // end method inventory value
    
    public String toString() {
    
    return String.format("item=%3d, artist=%-20s, units=%d, price=%.2f, value=%.2f", cdItem, cdArtist, cdStock, cdPrice, value());
    }
    
    } //end class CD
    
    class Inventory{
    
    	CD[]arOCD = new CD[50];
    
    // Add to inventory
    public void addToInventory(CD cd5) {
    }
    
    // Get inventory value
    public double getInventoryValue() {
    	Inventory myInventory = new Inventory();
    	myInventory.addToInventory(new CD(5, "Poison", 3, 11.99));
    
    // Print total value of inventory
    	System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());
    		return myInventory.getInventoryValue();}
    }

  8. #7
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Need Java help ASAP : (

    Your addToInventory method doesn't do anything. Also you aren't actually creating an Inventory object and galling getInventoryValue.

    You need to make an inventory object and code the addToInventory method to add them to the array.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. JAVA help needed ASAp
    By theRock in forum Java Help
    Replies: 4
    Last Post: 10-30-2009, 10:06 PM
  2. help ASAP pls...
    By mdeenny in forum C and C++
    Replies: 2
    Last Post: 10-29-2009, 07:06 PM
  3. Replies: 0
    Last Post: 10-19-2007, 09:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

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