0

Java beginner here. With the following code my else function automatically prints. So even before answering the question 'Do you want to buy the house with your partner? Type Yes / No' it's already throwing the else function out there.

//How much is the gross salary
    boolean partner;
    String partnerQuestion;
    double partnerSalary =0;
    System.out.print("Do you want to buy the house with your partner? Type Yes / No \n");
        while(true){
            partnerQuestion = sc.nextLine().trim().toLowerCase();
            if(partnerQuestion.equals("yes")){
                //how high is the loan                
                System.out.print("What is your partners´ anually gross salary? \n");
                partnerSalary = sc.nextDouble();
                partner = true;
                break;
            } 
            else if(partnerQuestion.equals("no")){
                partner = false;
                break;
            }  
            else{
                System.out.print("I did not understand you. Please try again.");
            }
        }

To give a good picture my if / else inside this while loop, does work.

boolean timeTF;
    double term;
    System.out.print("For how many years should the mortgage run? Choose between 10/15/20/25/30 \n");
        while(true){
            term = sc.nextDouble();
            if(term != 10 && term != 15 && term != 20 && term != 25 && term != 30){
                System.out.print("Please type 10/15/20/25/30, other values are not valid \n");
                timeTF = true;   
            } 
            else{  
                timeTF = false;
                break;
            }
        }

So my question is, what am I missing? Thanks in advance.

Marnick
  • 11
  • 2

0 Answers0