8 Replies - 710 Views - Last Post: 02 May 2012 - 05:14 AM Rate Topic: -----

#1 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

system out print error

Posted 02 May 2012 - 04:06 AM

 
     
 if (Gender.equals("female")) { 
    if (Hair.equals("green")) {

      if (Eyes.equals("brown")){ person = "A";

}
      else person="B";
    }
    if (Hair.equals("fair")) {
       if (Eyes.equals("brown")) person = "C";
       
    else person = "Sammy";
 }
}

    
System.out.print("person  " + person) ;






my problem is that i have design an if and else statement but my system.out.print does not work. the person you have chose it does not show in system.out.print.
i don't know what the error is or can someone show me. I'm a new learner to java.

Is This A Good Question/Topic? 0
  • +

Replies To: system out print error

#2 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: system out print error

Posted 02 May 2012 - 04:10 AM

Okay, is this the full program? Or just a snippet? If it's a snippet, please post your full program.
Because if it's the full program. You need to encase the code above in a class and a main method.

other than that, I see no error in this code.

This post has been edited by ILoveJava: 02 May 2012 - 04:11 AM

Was This Post Helpful? 0
  • +
  • -

#3 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: system out print error

Posted 02 May 2012 - 04:12 AM

View PostILoveJava, on 02 May 2012 - 04:10 AM, said:

Okay, is this the full program? Or just a snippet? If it's a snippet, please post your full program.
Because if it's the full program. You need to encase the code above in a class and a main method.

other than that, I see no error in this code.


it is an snippet of the code. what do you mean by encase the code in a class and a main method.im new to java and therefore i still don't fully understand yet
Was This Post Helpful? 0
  • +
  • -

#4 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: system out print error

Posted 02 May 2012 - 04:34 AM

Okay, are you able to post your entire program. Like the whole thing, not just a small snippet.
Was This Post Helpful? 0
  • +
  • -

#5 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: system out print error

Posted 02 May 2012 - 04:40 AM

View PostILoveJava, on 02 May 2012 - 04:34 AM, said:

Okay, are you able to post your entire program. Like the whole thing, not just a small snippet.



import javax.swing.JOptionPane;
public class ProgramSelection2{
   public static void main (String [] args) {
      
      String Hair,Gender,Eyes,Beard,person; 
      


     Hair = JOptionPane.showInputDialog(null, "Enter Brown or Fair Hair?");
     while (!(Hair.equalsIgnoreCase("Brown")||Hair.equalsIgnoreCase("Fair"))){
         Hair = JOptionPane.showInputDialog
         (null, "You Must Enter Brown or Fair ?") ;
     }
    
     Gender = JOptionPane.showInputDialog(null, "Enter Male or Female?");
     while (!(Gender.equalsIgnoreCase("Male")||Gender.equalsIgnoreCase("Female"))){
         Hair = JOptionPane.showInputDialog
         (null, "You Must Enter Male or Female ?") ;
     }
    
    Eyes = JOptionPane.showInputDialog(null, "Enter Brown or Blue?");
     while (!(Eyes.equalsIgnoreCase("Brown")||Eyes.equalsIgnoreCase("Blue"))){
         Eyes = JOptionPane.showInputDialog
         (null, "You Must Enter Brown or Blue ?") ;
     }

    
if (Gender.equals("male")) { 
     Beard = JOptionPane.showInputDialog(null, "Enter Beard or No Beard?");
     while (!(Beard.equalsIgnoreCase("Beard")||Beard.equalsIgnoreCase("No Beard"))){
         Beard = JOptionPane.showInputDialog
         (null, "Enter Beard or No Beard?") ;
     }
}

     
 if (Gender.equals("female")) { 
    if (Hair.equals("brown")) {

      if (Eyes.equals("brown")){ person = "uu";

}
      else person="ee";
    }
    if (Hair.equals("fair")) {
       if (Eyes.equals("brown")) person = "ll";
       
    else person = "mm";
 }
}

if (Gender.equals ("male")) { 
   if(Hair.equals ("brown")) {
      if (Eyes.equals("brown")) { 
        if (Beard.equals("no beard"))person = "n";
        else person = "c";
      }
      if (Eyes.equals("Blue")){
        if (Beard.equals("no beard")) person = "t";
        else person = "h";
      }
   }
   if(Hair .equals("Fair")) {
      if (Eyes .equals("Brown")) { 
        if (Beard .equals("no beard")) person = "X";
        else person = "S";
      }
      if (Eyes.equals("Brown")){
        if (Beard .equals("no beard")) person = "M";
        else person = "J";
      }
    }
} 
     
System.out.print(person + " Your Guess was " ) ;   
      
 }
}





my problem is that the person that i have chose it does not show in system.out.print
Was This Post Helpful? 0
  • +
  • -

#6 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: system out print error

Posted 02 May 2012 - 05:01 AM

Okay, your variables aren't being initialized. You need to create them as so.
String Hair,Gender,Eyes,Beard = "",person = "";

This post has been edited by ILoveJava: 02 May 2012 - 05:01 AM

Was This Post Helpful? 0
  • +
  • -

#7 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: system out print error

Posted 02 May 2012 - 05:04 AM

View PostILoveJava, on 02 May 2012 - 05:01 AM, said:

Okay, your variables aren't being initialized. You need to create them as so.
String Hair,Gender,Eyes,Beard = "",person = "";


the person you have chosen does not output in system.out.print. only output is your guess was. i need the person name
Was This Post Helpful? 0
  • +
  • -

#8 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: system out print error

Posted 02 May 2012 - 05:10 AM

When I ran the program, I got this.
n Your Guess was

n being variable for brown hair, male, brown eyes, no beard.
It's outputting, you just may not see it, because there isn't a proper name.
Was This Post Helpful? 0
  • +
  • -

#9 rik2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 09-April 12

Re: system out print error

Posted 02 May 2012 - 05:14 AM

View PostILoveJava, on 02 May 2012 - 05:10 AM, said:

When I ran the program, I got this.
n Your Guess was

n being variable for brown hair, male, brown eyes, no beard.
It's outputting, you just may not see it, because there isn't a proper name.


how do i get to see the name ? is it possible you can send the code that i sent you. if you can see the name because i cannot.

This post has been edited by rik2012: 02 May 2012 - 05:17 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1