Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-28-2009, 02:27 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
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.
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-28-2009, 02:50 AM
Senior Member
 
Join Date: Sep 2008
Posts: 564
Rep Power: 2
emceenugget is on a distinguished road
Default
is your file actually named "public class Inventory.java"? your file name should be the same as your class name...
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-28-2009, 03:23 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
Default public class Inventory.java
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-28-2009, 03:24 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
Default
I tried what you are thinking before and rearranged the public class but noting happened I still got the locale errors.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-28-2009, 03:25 AM
Senior Member
 
Join Date: Mar 2009
Posts: 392
Rep Power: 2
Singing Boyo is on a distinguished road
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!
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-28-2009, 03:38 AM
OrangeDog's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Cambridge, UK
Posts: 838
Rep Power: 2
OrangeDog is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-28-2009, 03:59 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-28-2009, 04:05 AM
Senior Member
 
Join Date: Mar 2009
Posts: 392
Rep Power: 2
Singing Boyo is on a distinguished road
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!
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-28-2009, 04:11 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
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++ )
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-28-2009, 04:56 AM
Senior Member
 
Join Date: Mar 2009
Posts: 392
Rep Power: 2
Singing Boyo is on a distinguished road
Default Incorrect for statement
Code:
for ( int number=0; counter; prodArray.list, counter++ )
this is incorrect. counter; is not a statement. it should be something like
Code:
for (int number=0; number<countUpTo;  number++)
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!
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-28-2009, 04:58 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
Default
Ok will try.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-28-2009, 04:59 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-28-2009, 05:04 AM
Senior Member
 
Join Date: Mar 2009
Posts: 392
Rep Power: 2
Singing Boyo is on a distinguished road
Default
Code:
for ( int number=0; counter; prodArraylist; counter ++)
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...
__________________
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!

Last edited by Singing Boyo; 05-28-2009 at 05:09 AM.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-28-2009, 06:22 AM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
Default Good try!
Originally Posted by Singing Boyo View Post
Code:
for ( int number=0; counter; prodArraylist; counter ++)
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.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-28-2009, 06:44 AM
Senior Member
 
Join Date: Mar 2009
Posts: 392
Rep Power: 2
Singing Boyo is on a distinguished road
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!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
different multiple public class and main class mr idiot New To Java 2 01-01-2009 01:10 PM
interface C programming with Java kapil1089theking AWT / Swing 8 09-11-2008 06:09 AM
what is the Priority for execution of Interface class and a Abstract class Santoshbk Advanced Java 0 04-02-2008 08:04 AM
Public class variable Java Tip Java Tips 0 12-03-2007 10:58 AM
illegal start of expression & class, interface, or enum expected silverq_82 New To Java 9 08-08-2007 08:16 PM


All times are GMT +2. The time now is 07:14 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org