Help With Simple Objects (EASY!)
So all I want to the console to print at the moment is
"Hello"
"Bonjour"
"false"
here's my main class:
Code:
public class French {
public static void main (String args[]){
frenchword hi = new frenchword("Hello","Bonjour", false);
System.out.println(hi.xEnglish);
System.out.println(hi.xFrench);
System.out.println(hi.xIsDone);
}
}
Here is my second class "frenchword"
Code:
public class frenchword{
public String xEnglish;
public String xFrench;
public boolean xIsDone;
public frenchword(Object English, Object French, Object IsDone) {
}
}
PS: I'm hoping to keep the part where you define the english french and IsDone in one line:
frenchword hi = new frenchword("Hello","Bonjour", false);
THANKS SO MUCH!
Re: Help With Simple Objects (EASY!)
In frenchword add:
this. xEnglish = English.toString();
and do that for all of the variables.
Re: Help With Simple Objects (EASY!)
Thanks that works. My only problem is the boolean, I looked up how to do it and finally thought this would work, however when it always returns false when I change
frenchword hi = new frenchword("Hello","Bonjour", false);
to
frenchword hi = new frenchword("Hello","Bonjour", true);
Heres my code so far for frenchword:
Code:
public class frenchword{
public String xEnglish;
public String xFrench;
public boolean xIsDone;
public frenchword(Object English, Object French, Object IsDone) {
this. xEnglish = English.toString();
this. xFrench = French.toString();
boolean xxIsDone = new Boolean(xIsDone).booleanValue();
this. xIsDone = xxIsDone;
}
}
Re: Help With Simple Objects (EASY!)
Is there any reason you're using Object as the type of the parameters for the constructor? Wouldn't it make more sense for it to be this? Code:
public frenchword(String english, String french, boolean isDone){...}
Quick note on conventions: frenchword should be FrenchWord as class-names are, by convention, CamelCase with the first letter as uppercase. Also, variables are usually camelCase with the first letter as lower-case.
Re: Help With Simple Objects (EASY!)
Thanks! Got everything to work, and for anyone with the same problem here is the fix.
Main Class
Code:
public class French {
public static void main (String args[]){
frenchword hi = new frenchword("Hello","Bonjour", true);
System.out.println(hi.xEnglish);
System.out.println(hi.xFrench);
System.out.println(hi.xIsDone);
}
}
frenchword class
Code:
public class frenchword{
public String xEnglish;
public String xFrench;
public boolean xIsDone;
public frenchword(String English, String French, boolean IsDone) {
this. xEnglish = English;
this. xFrench = French;
this. xIsDone = IsDone;
}
}