My program is not working as it should.
Purpose of the code: ask user name, gender, age - if age over 18, ask user if married. if user says yes, output Mr or Mrs in front of already given name.
I'm practicing nested if statements and getter/setter methods to return private variables.
I have tried: nesting the if statement that tests the gender and age status, then i tried using a switch statement instead of an if statement to test the marital status, then i tried nesting an if statement within the switch to test the gender and age. I have tried giving each of the if, else if clauses their own scanner input thinking that would just get it to function, but it did not.
I originally had the marital status as a getter/setter method, but took it out to simplify the problem.
I have looked for an answer, but it seems like the code is right, it just will not take the input!
The code I have is as follows:
package agemessage;
import java.util.Scanner;
public class AgeMessage {
public static void main(String[] args) {
info infoObject = new info(); //setter getter class to house input from user
Scanner in = new Scanner(System.in);
System.out.println("what is your name again?");
String input = in.nextLine();
infoObject.getName(input);
System.out.println("thanks, " + infoObject.setName() + " is that a boys name or a girls name?");
String gender = in.nextLine();
infoObject.getGender(gender);
System.out.println("How old are you " + infoObject.setName() + "?");
int ageInput = in.nextInt();
//infoObject.getAge(ageInput);
if (ageInput < 18) {
System.out.print("I shall just call you " + infoObject.setName() + ".");
System.exit(0);
} else if (ageInput >= 18) {
System.out.println("Are you married yet?");
}
//PROGRAM STOPS HERE -- DOES NOT EXECUTE INPUT
String status = in.nextLine();
if (status.equalsIgnoreCase("Y") && infoObject.setGender().equalsIgnoreCase("Girl")) {
System.out.println("I will have to call you Mrs. " + infoObject.setName() + ".");
} else if (status.equalsIgnoreCase("Y") && infoObject.setGender().equalsIgnoreCase("Boy")) {
System.out.println("I will have to call you Mr. " + infoObject.setName() + ".");
System.exit(0);
} else if (status.equalsIgnoreCase("N")) {
System.out.println("I will just call you " + infoObject.setName() + ".");
}
}// main end
}//class end
OUTPUT:
run: what is your name again? Carrie Ann Moss thanks, Carrie Ann Moss is that a boy's name or a girls name? girl How old are you Carrie Ann Moss? 40 Are you married yet? BUILD SUCCESSFUL (total time: 16 seconds)