Results 1 to 15 of 15
  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 E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum

    Hello How's it going over there? Everything here is fine. The weather is a little under the weather but other then that it ok. I have tried this one with you before and I forget the out come but it must not have worked because here I am again. Sorry for the inconvience but like everyone else I am pressed for time but I do have a little time to spare. So Great. Now I have this program and it states E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum expected
    import java.util.Locale;
    ^
    E:\IT 215 Java Programming\public class Inventory.java:40: class, interface, or enum expected
    import java.text.NumberFormat;
    ^
    2 errors
    And I am not real sure as to why. Well here is the code. I hope you find something.
    Java 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 i=0; i<n; i++ )
       {
       System.out.println(i);
       }
    
    {
    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

    I would really much appreciate it if you could find the errors and tell me why I am getting them.. I need this program to work.

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    is your file actually named "public class Inventory.java"? your file name should be the same as your class name...

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

    Default public class Inventory.java

    Quote Originally Posted by emceenugget View Post
    is your file actually named "public class Inventory.java"? your file name should be the same as your class name...
    Yes. The file is correct. What does that have to do with anything other then the class name that is not where I am getting the error. I get the error at Import.util.Locale and etc. I do not understand. This is due tommorrow.

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

    Default

    I tried what you are thinking before and rearranged the public class but noting happened I still got the locale errors.

  5. #5
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    If you could indicate the exact line in your code where the error occurs (just add something like //<<<<ERROR HERE>>>>) it would be much easier to help you...
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    File name should be just "Inventory.java"
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

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

    Default

    [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 i=0; i<n; i++ )
    {
    System.out.println(i);
    }

    {
    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
    //error code here
    import java.util.Locale;// error code here
    import java.text.NumberFormat;//error code here


    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

  8. #8
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    ok... are the classes in two separate files? If not, try doing that, may work then. If for any reason they need to be in the same file, the DVD class goes inside the Inventory class, and the imports causing the error go at the beginning of the file.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

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

    Default

    Hi You gave me a great Idea and I removed the Import.util.Locale from position line 39 and the other line I can't remember and put it in the front of the program. Removed completely from lines 39 and forty and re ran it and this is what i got. E:\IT 215 Java Programming\public class Inventory.java:25: not a statement
    for ( int number=0; counter; prodArray.list, counter++ )

  10. #10
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default Incorrect for statement

    Java Code:
    for ( int number=0; [color=red][b]counter[/b][/color]; prodArray.list, counter++ )
    this is incorrect. counter; is not a statement. it should be something like
    Java Code:
    for (int number=0; [color=green]number<countUpTo;  number++[/color])
    See The Java Tutorials: The for Statement for more information on for loops and how they work
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

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

    Default

    Ok will try.

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

    Default

    E:\IT 215 Java Programming\Inventory.java:25: not a statement
    for ( int number=0; counter; prodArraylist; counter ++)
    ^
    E:\IT 215 Java Programming\Inventory.java:25: ')' expected
    for ( int number=0; counter; prodArraylist; counter ++)
    ^
    E:\IT 215 Java Programming\Inventory.java:25: ';' expected
    for ( int number=0; counter; prodArraylist; counter ++)
    ^
    3 errors

    Tool completed with exit code 1

    I did what you suggested and I get back these 3 errors.

  13. #13
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Java Code:
    for ( int number=0; [color=red][b]counter; prodArraylist; counter ++[/b][/color])
    Still wrong... please read the tutorial from my last post. It will give you far more information than I can. One thing I will tell you is that if you do not have exactly 2 semicolons (';') within your brackets it will not work.

    EDIT: "One thing I will tell you is that if you do not have exactly 2 semicolons (';') within your brackets it will not work."

    This is not necessarily true (as the tutorial will tell you) If you use a colon (":") to iterate through an array, it would work as well...
    Last edited by Singing Boyo; 05-28-2009 at 04:09 AM.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

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

    Default Good try!

    Quote Originally Posted by Singing Boyo View Post
    Java Code:
    for ( int number=0; [color=red][b]counter; prodArraylist; counter ++[/b][/color])
    Still wrong... please read the tutorial from my last post. It will give you far more information than I can. One thing I will tell you is that if you do not have exactly 2 semicolons (';') within your brackets it will not work.

    EDIT: "One thing I will tell you is that if you do not have exactly 2 semicolons (';') within your brackets it will not work."

    This is not necessarily true (as the tutorial will tell you) If you use a colon (":") to iterate through an array, it would work as well...
    E:\IT 215 Java Programming\Inventory.java:25: cannot find symbol
    symbol : variable countUpTo
    location: class Inventory
    for (int number=0; number<countUpTo; number++)
    ^
    E:\IT 215 Java Programming\Inventory.java:28: cannot find symbol
    symbol : variable counter
    location: class Inventory
    System.out.println("Item Number: " + prodArray[counter].getitemNum());
    ^
    E:\IT 215 Java Programming\Inventory.java:29: cannot find symbol
    symbol : variable counter
    location: class Inventory
    System.out.println("Product Name: " + prodArray[counter].getName());
    ^
    E:\IT 215 Java Programming\Inventory.java:30: cannot find symbol
    symbol : variable counter
    location: class Inventory
    System.out.println("Quantity: " + prodArray[counter].getunits());
    ^
    E:\IT 215 Java Programming\Inventory.java:31: cannot find symbol
    symbol : variable counter
    location: class Inventory
    System.out.println("Unit Price: " + prodArray[counter].getprice());
    ^
    E:\IT 215 Java Programming\Inventory.java:32: cannot find symbol
    symbol : variable counter
    location: class Inventory
    System.out.println("Total Value: " + prodArray[counter].getvalue());
    ^
    6 errors

    Tool completed with exit code 1
    Good try but these are the errors that I am getting with your suggestion. It is late so I will turn in but try again in the morning with the tutorial. Thank you for your time.

  15. #15
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Well... I will just point out that countUpTo was not declared (it was pseudocode... the number you want to count up to with the for loop) and neither was counter (judging by the error messages.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. different multiple public class and main class
    By mr idiot in forum New To Java
    Replies: 2
    Last Post: 01-01-2009, 12:10 PM
  2. interface C programming with Java
    By kapil1089theking in forum AWT / Swing
    Replies: 8
    Last Post: 09-11-2008, 05:09 AM
  3. Replies: 0
    Last Post: 04-02-2008, 07:04 AM
  4. Public class variable
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:58 AM
  5. Replies: 9
    Last Post: 08-08-2007, 07:16 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
  •