Results 1 to 17 of 17
- 05-28-2009, 05:41 AM #1
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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.
-
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?
-
Also, the likely solution to your problem, is to place DVD in its own file.
- 05-28-2009, 08:00 AM #4
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Some people... Cross-posted at this page in New to Java..
Tlouvierre, you need to do some reading of forum FAQ's/guidelinesIf 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!
- 05-28-2009, 12:41 PM #5
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
- 05-28-2009, 12:45 PM #6
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
Solved one error but one still exist. Thank you. Please look again.
[/code]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
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.
- 05-28-2009, 01:10 PM #7
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
- 05-28-2009, 01:14 PM #8
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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
- 05-28-2009, 02:11 PM #9
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
- 05-28-2009, 02:14 PM #10
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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!
- 05-28-2009, 02:39 PM #11
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
public static
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.
- 05-28-2009, 02:48 PM #12
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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.
And the error that I am getting now is. E:\IT 215 Java Programming\Inventory.java:36: class, interface, or enum expectedJava 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
}// 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.
- 05-28-2009, 02:57 PM #13
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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?
- 05-28-2009, 03:06 PM #14
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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.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
-
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.
- 05-28-2009, 03:35 PM #16
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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.
Good Luck to whoever needs it. God Bless!!!!!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
-
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
-
E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum
By tlouvierre in forum New To JavaReplies: 14Last Post: 05-28-2009, 05:44 AM -
interface C programming with Java
By kapil1089theking in forum AWT / SwingReplies: 8Last Post: 09-11-2008, 05:09 AM -
'class' or 'interface' expected
By denisdoherty in forum New To JavaReplies: 23Last Post: 04-22-2008, 06:13 PM -
class or interface expected -compile err
By ravi503 in forum Java ServletReplies: 1Last Post: 03-26-2008, 11:45 AM -
illegal start of expression & class, interface, or enum expected
By silverq_82 in forum New To JavaReplies: 9Last Post: 08-08-2007, 07:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks