Results 1 to 17 of 17
  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\Inventory.java:36: class, interface, or enum expected

    [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; number<countUpTo; number++)

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

    I am having a hard figuring out these errors. i have spent the whole day online New to Java but no dice. So I figured that I should try Advanced Java. Hello How are you today? This program is supposed to alot of things. It is required in class but I can not get it to compile and I know that you do not need the class criteria to get it to compile. So I won't bore you unless you feel that you need it? On lines 36 and 37 is where the problem lies. Look for the error here marks.

  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 to use code tags if you want others to read your code posts. The end tag should be [/cod&#101;] not [cod&#101;]. You can edit your post above and you'll see it will make a big difference in readability, and this is for your own benefit: if your code is easier to read, more will read it which is what you want, right?

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

    Default

    Also, the likely solution to your problem, is to place DVD in its own file.

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

    Default

    Some people... Cross-posted at this page in New to Java..

    Tlouvierre, you need to do some reading of forum FAQ's/guidelines
    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!

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

    Default Code Tags

    Quote Originally Posted by Fubarable View Post
    Please learn to use code tags if you want others to read your code posts. The end tag should be [/code] not [code]. You can edit your post above and you'll see it will make a big difference in readability, and this is for your own benefit: if your code is easier to read, more will read it which is what you want, right?
    Top of the morning to you. Sorry I just misplaces my fingers. It won't happen again.:eek:

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

    Smile Solved one error but one still exist. Thank you. Please look again.

    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 number=0; number<countUpTo<10000;  number++)
    
    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// line 33 E:\IT 215 Java Programming\Inventiry.java:33: class, interface, or enum expected
    } // end class Inventory
    
    // Class DVD holds DVD information// line 34
    import java.util.Locale;// line 35
    import java.text.NumberFormat;// line 36 E:\IT 215 Java Programming\Inventiry.java:36: class, interface, or enum expected
    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
    [/code]

    Hah I got my tag right. Anyway not for you Singboy. If you look line 33 there is only a comment there. So I do not understand how that could be a problem. Then on line 36 well import.text.Numberformat is on that line. I will change it back to text instead of util and see if that helps. Be right back.
    Last edited by tlouvierre; 05-28-2009 at 01:13 PM.

  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 tags

    Quote Originally Posted by Fubarable View Post
    Please learn to use code tags if you want others to read your code posts. The end tag should be [/code] not [code]. You can edit your post above and you'll see it will make a big difference in readability, and this is for your own benefit: if your code is easier to read, more will read it which is what you want, right?
    I swear that i am putting the code tage but for some reason they are not showing up. Do I need to resubmit the file or no?

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

    Default

    Are you messin with me? Because I tried to edit the field and it is there [/code] plain as day. I know you have been up all night and are getting me back for going to sleep. HA

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

    Red face Trying out your solution will let you know if it works. Thanks for the advice

    Quote Originally Posted by Fubarable View Post
    Also, the likely solution to your problem, is to place DVD in its own file.
    I see where there is a class but no public so I am going to try and make it public and hope that it clears up my problems. Thank s again.

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

    Default

    Sing boyo I have read everything pertaining to me and I checked the tutorial 5 and its 1300 pages long. In your response you have not been point specific enough for me to look anything up but you have been helpful. If you could give me the name of the instance error code like API, give me some where to look other than a 1300 pages layout it sure would help. I am no stranger to hard work but that is impossible to read in a day. Thanks again!

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

    Talking public static

    Quote Originally Posted by Fubarable View Post
    Also, the likely solution to your problem, is to place DVD in its own file.
    Well Fubarable I made DVD public and that was fine. Except it did not cure the problem. The problem is one of these:illegal start of expression
    The error message will point to perfectly good code. Look just ahead of it for a missing } or ;
    static int x = 0; Static variables have to be defined outside all methods inside a class.
    you wrote x + = 2; instead of x += 2;
    you wrote case: STRAWBERRY instead of case STRAWBERRY :
    You nested a method inside another method.

    On lines 35 and 36. It says that I have illegal start. Once I tried to move the locale and numberformat to the beginning but I was still getting the class, interface, enum error. So I put back and no change. Working very hard just not understanding. I though that the import had to distinguished for the public class DVD. Now I am not so sure.

  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

    I have made some changes and I think you will be pleased. I have the errors down to one. Can you help? Respectfully yours Tiffany.
    Java Code:
    import java.util.Scanner;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Locale;// line 35
    import java.text.NumberFormat;// line 36 E:\IT 215 Java Programming\Inventiry.java:36: class, interface, or enum expected
    
    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; number<countUpTo<10000;  number++)
    {
    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
    public 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
    And the error that I am getting now is. E:\IT 215 Java Programming\Inventory.java:36: class, interface, or enum expected
    }// Class DVD holds DVD information
    But this is just a comment line so is another } that is needed. I don't know my eyes are tired as are yours I am sure.

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

    Default

    There is something wrong with my for loop and I took Singboyo advice and erased the old for loop that I had. Could you look in that area?

  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

    Java Code:
    E:\IT 215 Java Programming\Inventory.java:38: class DVD is public, should be declared in a file named DVD.java
    public class DVD
           ^
    E:\IT 215 Java Programming\Inventory.java:23: cannot find symbol
    symbol  : variable list
    location: class DVD[]
    for (int number=0; prodArray.list;  counter++)
                                ^
    E:\IT 215 Java Programming\Inventory.java:23: cannot find symbol
    symbol  : variable counter
    location: class Inventory
    for (int number=0; prodArray.list;  counter++)
                                        ^
    E:\IT 215 Java Programming\Inventory.java:25: cannot find symbol
    symbol  : variable countUpTo
    location: class Inventory
    System.out.println("Item Number: " + countUpTo[counter].getitemNum());
                                         ^
    E:\IT 215 Java Programming\Inventory.java:25: cannot find symbol
    symbol  : variable counter
    location: class Inventory
    System.out.println("Item Number: " + countUpTo[counter].getitemNum());
                                                   ^
    E:\IT 215 Java Programming\Inventory.java:26: cannot find symbol
    symbol  : variable counter
    location: class Inventory
    System.out.println("Product Name: " + prodArray[counter].getName());
                                                    ^
    E:\IT 215 Java Programming\Inventory.java:27: cannot find symbol
    symbol  : variable counter
    location: class Inventory
    System.out.println("Quantity: " + prodArray[counter].getunits());
                                                ^
    E:\IT 215 Java Programming\Inventory.java:28: cannot find symbol
    symbol  : variable counter
    location: class Inventory
    System.out.println("Unit Price: " + prodArray[counter].getprice());
                                                  ^
    E:\IT 215 Java Programming\Inventory.java:29: cannot find symbol
    symbol  : variable counter
    location: class Inventory
    System.out.println("Total Value: " + prodArray[counter].getvalue());
                                                   ^
    9 errors
    
    Tool completed with exit code 1
    I thought by making DVD public it would establish it as java. So what am I doing wrong. There is a statement public class DVD how do I make it a Java file. I am not saying by any means that this will solve all of my problems but maybe.

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

    Default

    Two questions:
    1) Are DVD and Inventory still in the same file?
    2) Is your code always without indentation? If so, you may be able to read it, but most of us are used to reading code that is properly (3-4 spaces) indented. Why not make your posted code easier for us to read? Again, more of us will read it if you do.

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

    Default

    I got it I got it I got it to work! Here is the finished program and thanks for telling me that I was being published the whole time.
    Java Code:
    import java.util.Scanner;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Locale;// line 35
    import java.text.NumberFormat;// line 36 E:\IT 215 Java Programming\Inventiry.java:36: class, interface, or enum expected
    
    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=1; number<10000;  number++)
    {
    System.out.println("Item Number: " + prodArray[number].getitemNum());
    System.out.println("Product Name: " + prodArray[number].getName());
    System.out.println("Quantity: " + prodArray[number].getunits());
    System.out.println("Unit Price: " + prodArray[number].getprice());
    System.out.println("Total Value: " + prodArray[number].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
    Good Luck to whoever needs it. God Bless!!!!!

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

    Default

    I see that you've been told multiple times to place both classes in their own file, but I don't see any indication that you've tried to follow this advice or that you intend to. You may wish to at least acknowledge that you've read it and let us know if or why you don't want to follow it.
    Last edited by Fubarable; 05-28-2009 at 03:58 PM.

Similar Threads

  1. Replies: 14
    Last Post: 05-28-2009, 05:44 AM
  2. interface C programming with Java
    By kapil1089theking in forum AWT / Swing
    Replies: 8
    Last Post: 09-11-2008, 05:09 AM
  3. 'class' or 'interface' expected
    By denisdoherty in forum New To Java
    Replies: 23
    Last Post: 04-22-2008, 06:13 PM
  4. class or interface expected -compile err
    By ravi503 in forum Java Servlet
    Replies: 1
    Last Post: 03-26-2008, 11:45 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
  •