• Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal start of expression error  RSS feed

 
Mark Georgevich
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The below code is not compiling. Next to "private string itemName" NetBeans keeps giving me an error "illegal start of expression". This is what I am supposed to do:
Thanks for any assistance.


Build the ItemToPurchase class with the following specifications:

Private fields
String itemName - Initialized in default constructor to "none"
int itemPrice - Initialized in default constructor to 0
int itemQuantity - Initialized in default constructor to 0

Default constructor
Public member methods (mutators & accessors)
setName() & getName()
setPrice() & getPrice()
setQuantity() & getQuantity()

(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call scnr.nextLine(); to allow the user to input a new string.




 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please format your code using code tag. I use your code and found no error.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next to "private string itemName" 

Java is case sensitive. String is spelled with S not s
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main method must be within the body of a class ie:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!