Results 1 to 11 of 11
  1. #1
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default Inventory Errors

    [code]
    import java.util.Scanner;
    import java.util.Arrays;
    import java.util.Collections;


    public class Inventory {

    public static void main(String args []) {
    //create new object
    DVD mydvd = new DVD();
    //create and intialize arrayof products
    DVD[] prodArray = new DVD[6];
    prodArray[0] = new DVD("Action",15,59,22.00);
    prodArray[1] = new DVD("Westerns",26,68,16.00);
    prodArray[2] = new DVD("Drama",22, 71, 15.00);
    prodArray[3] = new DVD("Comedy",33, 50, 19.00);
    prodArray[4] = new DVD("Sci-Fi",66, 42, 14.00);
    prodArray[5] = new DVD("Horror",27, 53, 24.00);


    //For each array element, output value
    for (int number=0; counter;prodArray.list counter++ )


    {
    System.out.println("Item Number: " + prodArray[counter].getitemNum());
    System.out.println("Product Name: " + prodArray[counter].getName());
    System.out.println("Quantity: " + prodArray[counter].getunits());
    System.out.println("Unit Price: " + prodArray[counter].getprice());
    System.out.println("Total Value: " + prodArray[counter].getvalue());
    System.out.println(); //blank line to seperate products
    }//end array output
    } //end main

    } // end class Inventory
    // Class DVD holds DVD information
    import java.util.Locale;
    import java.text.NumberFormat;


    class DVD
    {
    public String name;
    public Integer itemNum;
    public Integer units;
    public Double price;
    //default constructor
    public DVD()
    {
    name = "";
    itemNum = 0;
    units = 0;
    price = 0.00;
    }//end default constructor
    //Parameterized Constructor
    public DVD(String name, Integer itemNum, Integer units, Double price)
    {
    this.name = name;
    this.itemNum = itemNum;
    this.units = units;
    this.price = price;
    }//end constructor

    //Set product information
    public void setName(String name) {
    this.name = name;
    }
    public String getName()
    {
    return name;

    }

    public void setitemNum ( int itemNum )
    {
    this.itemNum = itemNum;
    }

    public Integer getitemNum()
    {
    return itemNum;
    }
    public void setunits ( int units )
    {
    this.units = units;
    }
    public Integer getunits()
    {
    return units;
    }
    public void setprice ( Double price )
    {
    this.price = price;
    }
    public Double getprice()
    {
    return price;
    }
    public Double getvalue()
    {
    return (units * price);
    }


    // the compareTo method is used to implement the Comparable interface. This enables us to sort a list of Products using Arrays.sort()
    // this method returns -1, 0, or 1 depending on if the compared to object should appear before, the same, or after the current item
    public int compareTo (Object o)
    {
    DVD d = (DVD) o;
    return name.compareTo(getName());
    }

    // returns a string representation of the DVD
    public String toString()
    {
    return "DVD Name : " + getName() + " "
    + "DVD Number : " + getitemNum() + " "
    + "DVD Price : " + NumberFormat.getCurrencyInstance(Locale.US).format (getprice()) + " "
    + "Number in Stock : " + getunits() + " "
    + "Value of inventory : " + NumberFormat.getCurrencyInstance(Locale.US).format (getvalue());
    }

    }//end Class DVD

    E:\IT 215 Java Programming\Inventory.java:22: not a statement
    for (int number=0; counter;prodArray.list counter++ )
    ^
    E:\IT 215 Java Programming\Inventory.java:22: ')' expected
    for (int number=0; counter;prodArray.list counter++ )
    ^
    E:\IT 215 Java Programming\Inventory.java:22: ';' expected
    for (int number=0; counter;prodArray.list counter++ )
    ^
    E:\IT 215 Java Programming\Inventory.java:37: class, interface, or enum expected
    import java.util.Locale;
    ^
    E:\IT 215 Java Programming\Inventory.java:38: class, interface, or enum expected
    import java.text.NumberFormat;
    ^
    5 errors

    Tool completed with exit code 1
    [code]

    I am getting these errors and do not know why. I have tried to rewrite the for loop but no dice. I get less errors but then I am given the last two errors only yet if I remove the last two calls locale and numberformat I get even more errors. Do On Friday.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please learn how to use code tags correctly since without correct tags, your code loses its formatting. The bottom tag has a backslash:

    [code]
    //.. your code goes here
    [/code]

    Also, you'll want to read the sun tutorial on how to use for loops to see how to use them correctly. You can find this here: for statement tutorial

    best of luck

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Study...

    I think this has been commented to you before... you have to learn to crawl before you can walk....
    Please pay to Fubarable's suggestion... study the link about "for" loops.
    Also, your implementation a the array is all wrong. Please study the following link to learn how to use the Array class:
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    (hint: arrays can only contain one type of element)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    And also, at least try to identify what the error is. You can find more about the error message you get, and it's another way to learn.

  5. #5
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    805
    Rep Power
    6

    Default

    Hi,
    I have corrected your code.As suggested by Eranga,only with errors you can learn the language.Go thru "java Complete Reference" to know the basics.
    Please run the below corrected code.

    -Regards
    Ramya

    Java Code:
    import java.util.Scanner;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Locale;
    import java.text.NumberFormat;
    
    public class Inventory {
    
    public static void main(String args []) {
    //create new object
    DVD mydvd = new DVD();
    //create and intialize arrayof products
    DVD[] prodArray = new DVD[6];
    prodArray[0] = new DVD("Action",15,59,22.00);
    prodArray[1] = new DVD("Westerns",26,68,16.00);
    prodArray[2] = new DVD("Drama",22, 71, 15.00);
    prodArray[3] = new DVD("Comedy",33, 50, 19.00);
    prodArray[4] = new DVD("Sci-Fi",66, 42, 14.00);
    prodArray[5] = new DVD("Horror",27, 53, 24.00);
    
    
    //For each array element, output value
    for (int counter=0; counter<prodArray.length;counter++ )
    
    
    {
    System.out.println("Item Number: " + prodArray[counter].getitemNum());
    System.out.println("Product Name: " + prodArray[counter].getName());
    System.out.println("Quantity: " + prodArray[counter].getunits());
    System.out.println("Unit Price: " + prodArray[counter].getprice());
    System.out.println("Total Value: " + prodArray[counter].getvalue());
    System.out.println(); //blank line to seperate products
    }//end array output
    } //end main
    
    } // end class Inventory
    // Class DVD holds DVD information
    
    
    
    class DVD
    {
    public String name;
    public Integer itemNum;
    public Integer units;
    public Double price;
    //default constructor
    public DVD()
    {
    name = "";
    itemNum = 0;
    units = 0;
    price = 0.00;
    }//end default constructor
    //Parameterized Constructor
    public DVD(String name, Integer itemNum, Integer units, Double price)
    {
    this.name = name;
    this.itemNum = itemNum;
    this.units = units;
    this.price = price;
    }//end constructor
    
    //Set product information
    public void setName(String name) {
    this.name = name;
    }
    public String getName()
    {
    return name;
    
    }
    
    public void setitemNum ( int itemNum )
    {
    this.itemNum = itemNum;
    }
    
    public Integer getitemNum()
    {
    return itemNum;
    }
    public void setunits ( int units )
    {
    this.units = units;
    }
    public Integer getunits()
    {
    return units;
    }
    public void setprice ( Double price )
    {
    this.price = price;
    }
    public Double getprice()
    {
    return price;
    }
    public Double getvalue()
    {
    return (units * price);
    }
    
    
    // the compareTo method is used to implement the Comparable interface. This enables us to sort a list of Products using Arrays.sort()
    // this method returns -1, 0, or 1 depending on if the compared to object should appear before, the same, or after the current item
    public int compareTo (Object o)
    {
    DVD d = (DVD) o;
    return name.compareTo(getName());
    }
    
    // returns a string representation of the DVD
    public String toString()
    {
    return "DVD Name : " + getName() + " "
    + "DVD Number : " + getitemNum() + " "
    + "DVD Price : " + NumberFormat.getCurrencyInstance(Locale.US).format (getprice()) + " "
    + "Number in Stock : " + getunits() + " "
    + "Value of inventory : " + NumberFormat.getCurrencyInstance(Locale.US).format (getvalue());
    }
    
    }//end Class DVD
    Ramya:cool:

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hi Ramya, rather just correcting a code, it's much much better to give some hints to workout him/her self. Otherwise they couldn't learn in the correct way. :)

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default That is not a good idea

    Ramya... please do not do that. Do not correct ALL the OPs code. It is OK to give hints, suggestions, code snippets, links etc, but is not good to give complete solutions or correct all the OPs code. It is to much temptation for the OP to cut, paste and forget. There is no learning process!!! How do you expect the OP to learn if you correct all the code for him? How is the OP going to learn look up classes and methods.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    805
    Rep Power
    6

    Default

    Sorry Friends!!!!!

    I will not do....
    Ramya:cool:

  9. #9
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    There is also another thing to notice is that tlouvierre never comes back and says "thanks" for the help that was received.... we never know what the final result is.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  10. #10
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    805
    Rep Power
    6

    Default

    Hi CJSL,
    I will not repeat this.Sorry.....
    -Regards
    Ramya
    Ramya:cool:

  11. #11
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    Hey... no problem... you now understand and that's what important. My last message was was more pointed torwards tlouvierre.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Inventory Program
    By tlouvierre in forum New To Java
    Replies: 5
    Last Post: 05-17-2009, 05:09 AM
  2. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  3. adding GUI to Inventory
    By voyager91 in forum New To Java
    Replies: 8
    Last Post: 02-01-2009, 05:20 AM
  4. Help with Errors in Inventory Program
    By ljk8950 in forum AWT / Swing
    Replies: 3
    Last Post: 08-08-2008, 11:49 PM
  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
  •