I am trying to replicate this code that I did in the console in GUI.
if (age <18 && feelings.toUpperCase().equals("SAD")){
System.out.println(phrase.sadQuotesBefore18[rand.nextInt(2)]);
} else if (age >= 18 && feelings.toUpperCase().equals("SAD") ) {
System.out.println(phrase.sadQuotesAfter18[rand.nextInt(3)]);
} else if (age <18 && feelings.toUpperCase().equals("ANGRY")){
System.out.println(phrase.angryQuotesBefore18[rand.nextInt(2)]);
} else if (age >= 18 && feelings.toUpperCase().equals("ANGRY")){
System.out.println(phrase.angryQuotesAfter18[rand.nextInt(8)]);
} else if (age < 18 && feelings.toUpperCase().equals("HAPPY")){
System.out.println(phrase.happyQuotesBefore18[rand.nextInt(2)]);
} else if (age >= 18 && feelings.toUpperCase().equals("HAPPY")){
System.out.println(phrase.happyQuotesAfter18[rand.nextInt(4)]);
} else {
System.out.println("You have entered and unknown combination, please try again");
}
As shown below. I realise in the code below I cannot get the else if and else statements as shown above to work. Only the if statement as shown below works. I am new to this so any assistance would be appreciated.
submitButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (agebox.getText().equals("<=18") && feelings.equals("Sad")) {
}
showAlert(AlertType.CONFIRMATION, gridPane.getScene().getWindow(), "Your Quote!", phrase.sadQuotesBefore18[rand.nextInt(3)]);
}
}