Results 1 to 5 of 5
Thread: Help With Simple Objects (EASY!)
- 10-15-2011, 11:59 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 56
- Rep Power
- 0
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:
Java 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"
PS: I'm hoping to keep the part where you define the english french and IsDone in one line:Java Code:public class frenchword{ public String xEnglish; public String xFrench; public boolean xIsDone; public frenchword(Object English, Object French, Object IsDone) { } }
frenchword hi = new frenchword("Hello","Bonjour", false);
THANKS SO MUCH!
- 10-16-2011, 12:04 AM #2
Re: Help With Simple Objects (EASY!)
In frenchword add:
this. xEnglish = English.toString();
and do that for all of the variables.
- 10-16-2011, 12:27 AM #3
Member
- Join Date
- Sep 2011
- Posts
- 56
- Rep Power
- 0
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:
Java 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; } }
- 10-16-2011, 12:35 AM #4
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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?
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.Java Code:public frenchword(String english, String french, boolean isDone){...}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!
- 10-16-2011, 12:40 AM #5
Member
- Join Date
- Sep 2011
- Posts
- 56
- Rep Power
- 0
Re: Help With Simple Objects (EASY!)
Thanks! Got everything to work, and for anyone with the same problem here is the fix.
Main Class
frenchword classJava 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); } }
Java 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; } }
Similar Threads
-
Simple program, probably easy solution?
By falkon114 in forum New To JavaReplies: 6Last Post: 01-18-2011, 08:31 PM -
Simple SQL update doesn't work :( (Probebly easy error)
By Addez in forum New To JavaReplies: 4Last Post: 08-23-2010, 03:19 AM -
Simple question about objects.
By shroomiin in forum New To JavaReplies: 10Last Post: 10-10-2009, 02:33 AM -
A Simple way to use JButtons and place objects in a JFrame
By Singing Boyo in forum Java TipReplies: 0Last Post: 03-10-2009, 09:55 AM -
Need help with a simple Java thing involving array of objects
By Jeremy8 in forum New To JavaReplies: 5Last Post: 02-25-2009, 07:14 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks