Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Singing Boyo

Thread: Help With Simple Objects (EASY!)

  1. #1
    skaterboy987 is offline Member
    Join Date
    Sep 2011
    Posts
    56
    Rep Power
    0

    Default 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"

    Java 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!

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: Help With Simple Objects (EASY!)

    In frenchword add:
    this. xEnglish = English.toString();
    and do that for all of the variables.

  3. #3
    skaterboy987 is offline Member
    Join Date
    Sep 2011
    Posts
    56
    Rep Power
    0

    Default 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;
    
    		}
    }

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default 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?
    Java 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.
    skaterboy987 likes this.
    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!

  5. #5
    skaterboy987 is offline Member
    Join Date
    Sep 2011
    Posts
    56
    Rep Power
    0

    Default Re: Help With Simple Objects (EASY!)

    Thanks! Got everything to work, and for anyone with the same problem here is the fix.


    Main Class
    Java 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
    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

  1. Simple program, probably easy solution?
    By falkon114 in forum New To Java
    Replies: 6
    Last Post: 01-18-2011, 08:31 PM
  2. Replies: 4
    Last Post: 08-23-2010, 03:19 AM
  3. Simple question about objects.
    By shroomiin in forum New To Java
    Replies: 10
    Last Post: 10-10-2009, 02:33 AM
  4. Replies: 0
    Last Post: 03-10-2009, 09:55 AM
  5. Replies: 5
    Last Post: 02-25-2009, 07:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •