To learn how to do this in java you have to really understand how object orientated programming works, I will try and explain it here but watching some tutorials or reading some reference books will give you a more full understanding.
So in java you have a class, and this is something generic (like for instance a person), that class contains attributes that all people would have, called variables, and actions that all people can do, called methods, you then create objects of this class, and set the specific variables for that object, so I could create an object of the class person, and set it's hair color to brown and it's eyes to green. Then I can make that person do stuff by calling the persons methods, for your program the stuff you want them to do is answer questions, so you would have a method called ask question, this would take in a string parameter of the question that is being asked, and the method body would contain something that works out what the question is and asks according to the attributes that have been set. So an example of your person class would be
public class Person{
//attributes
String hairColor = null;
String eyeColor = null;
//actions
public void askQuestion(String question){
//check to see if the attributes have been set yet
if(hairColor == null || eyeColor == null){
System.out.println("you must set variables before asking a question");
}
//check to see what the question was
if(question.equals("How are you feeling")){
//no idea why blonde people feel fine and others don't lol
if(hairColor.equals("blonde")){
System.out.println("I am fine thankyou");
//were done with the method, get out of here
return;
}
if(hairColor.equals("brown")){
System.out.println("I feel so down and depressed with life");
//were done with the method, get out of here
return;
//execute this if the hair color wasn't blonde or brown (a cleaner way to do this repeated if's followed by an else if none were true is in a switch
//statement, this bit of code goes in the defualt part (google it))
}else{
System.out.println("Sorry, I don't know what to do if my hair color is" + hairColor);
return;
}
}else{
System.out.println("I couldn't be bothered to code in any more questions lol");
}
}
}
Now to use that code we need to create an object of person, we do this in a main method (this is the method in java that runs first, you cannot run a program if it doesn't contain one of these, it is static which means it isn't object orientated (it isn't something that all objects of a generic type can do it's just a utility method put in that class for organizational purposes).
So we will create a new class for that method to be in like so:
public class main{
//main method
public static void main(String args[]{
//create an object of person
Person examplePerson = new Person();
//set example persons attributes
examplePerson.hairColor = "brown";
examplePerson.eyeColor = "green";
//ask example person a question
examplePerson.askQuestion("How are you feeling");
}
}
So the output in the console from this would be: I feel so down and depressed with life