Results 1 to 15 of 15
- 05-28-2009, 01:27 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\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.
- 05-28-2009, 01:50 AM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
is your file actually named "public class Inventory.java"? your file name should be the same as your class name...
- 05-28-2009, 02:23 AM #3
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
- 05-28-2009, 02:24 AM #4
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
I tried what you are thinking before and rearranged the public class but noting happened I still got the locale errors.
- 05-28-2009, 02:25 AM #5
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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!
- 05-28-2009, 02:38 AM #6
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
- 05-28-2009, 02:59 AM #7
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
[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
- 05-28-2009, 03:05 AM #8
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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!
- 05-28-2009, 03:11 AM #9
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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++ )
- 05-28-2009, 03:56 AM #10
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Incorrect for statement
this is incorrect. counter; is not a statement. it should be something likeJava Code:for ( int number=0; [color=red][b]counter[/b][/color]; prodArray.list, counter++ )
See The Java Tutorials: The for Statement for more information on for loops and how they workJava Code:for (int number=0; [color=green]number<countUpTo; number++[/color])
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!
- 05-28-2009, 03:58 AM #11
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
Ok will try.
- 05-28-2009, 03:59 AM #12
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: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.
- 05-28-2009, 04:04 AM #13
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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.Java Code:for ( int number=0; [color=red][b]counter; prodArraylist; counter ++[/b][/color])
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!
- 05-28-2009, 05:22 AM #14
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
Good try!
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.
- 05-28-2009, 05:44 AM #15
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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
-
different multiple public class and main class
By mr idiot in forum New To JavaReplies: 2Last Post: 01-01-2009, 12:10 PM -
interface C programming with Java
By kapil1089theking in forum AWT / SwingReplies: 8Last Post: 09-11-2008, 05:09 AM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM -
Public class variable
By Java Tip in forum Java TipReplies: 0Last Post: 12-03-2007, 09:58 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