r/javahelp • u/Seder777 • Sep 06 '15
I need help
For my assignment I need to do this....DECLARE AN INSTANCE VARIABLE CALLED NAME THAT CAN CONTAIN A VALUE SUCH AS "EGGS"....I have no idea where to start. If someone could help me get started hopefully I can finish the assignment. Thanks everyone
0
Upvotes
4
u/desrtfx Out of Coffee error - System halted Sep 06 '15
Now, you have a value
"Eggs"that is encompassed in double quotes". This already is a hint on the type of the variable.In Java, Strings are encompassed by double quotes.
So, you need to declare a variable, called
name, that can hold aString "Eggs".What you need to do is:
You need another instance variable
costthat can hold a value of1.21. The decimal point again hints the data type:double.So, the next instance variable is:
Last, you need an instance variable
aisleNumthat can hold a value such as5. The missing decimal point hints that you should use anint:Now, you need the constructor that takes the parameters
name,cost,aisleNum.Constructors are methods that have the same name as the class: