Newbie questions about lesson on class implementation
Hey everybody,
I have been learning Java onlin for about a week now.
here is the program I am trying to get to work
Code :
class OfficeLights {
char Status = Off;
char Status = On;
void changeStatus(char newValue) {
status = newValue;
}
void printStates() {
System.out.println("Status:"+Status);
}
}
class CoffeeMug {
char lid = Open;
char Lid = Closed;
char Contents = Empty;
char Contents = Coffee;
char Contents = Tea;
void changeLid(char newValue) {
lid = newValue;
}
void changeContents(char newValue) {
Contents = newValue;
}
void printStates() {
System.out.println("lid:"+lid+" Contents:"+Contents);
}
}
class OfficeLightsCoffeeMug {
public static void main(String[] JD) {
OfficeLights light1 = new OfficeLights();
light1.changeStatus(On);
light1.printStates();
CoffeeMug mug1 = new CoffeeMug();
mug1.changeLid(Closed);
mug1.changeContents(Coffee);
mug1.printStates();
}
}
It wont compile, I get 14 error messages.
I have attached a screenshot of the errors I am getting when I try to compile.
Any advice on this particular program &| some newbie tips/advice in general would be very welcome,
Thanks!
P.S. I hope this is the right topic to post under, sorry if I commited a faux pas...
Re: Newbie questions about lesson on class implementation
For starters,
is not a proper statement. char is a primitive whose syntax is:
If you just want something to store an off/on value, look into using a boolean
For more information on primitives which will help you fix your errors, see Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)