jeudi 13 février 2020

How do i get my Java if statment to work? [duplicate]

I need to create a code where it takes the answers to yes or now questions and gives an answer back. In the one that I am doing I am asking what the user takes in his/her coffee and the program is coming back with the name of the drink. For example if i say no to everything it is suppose to print out expresso but it wont print anything. Any ideas?

 import java.util.Scanner;
 public class Java
 {
 public static void main(String[]args)
 {
    Scanner Scan = new Scanner(System.in);
    System.out.println("Does the drink contain steamed milk?(yes/no)");
    String steamedMilk =Scan.nextLine();
    System.out.println("Does the drink contain milk foam?(yes/no)");
    String milkFoam = Scan.nextLine();
    System.out.println("Does the drink contain water?(yes/no)");
    String water =Scan.nextLine();
    System.out.println("Does the drink contain chocolate syrup?(yes/no)");
    String chocolate = Scan.nextLine();
    System.out.println("Does the drink contain whipped cream?(yes/no)");
    String whippedCream =Scan.nextLine();
    System.out.println("Does the drink contain steamed half and half?(yes/no)");
    String halfAndHalf = Scan.nextLine();
    if           (steamedMilk=="no"||chocolate=="no"||milkFoam=="no"||water=="no"||whippedCream=="no"||halfAndHalf=="   no") {
        System.out.println("EXPRESSO");
    }
        else if (steamedMilk=="yes"||chocolate=="no"||milkFoam=="no"||water=="no"||whippedCream=="no"||halfAndHalf=="no") {
            System.out.println("FLAT WHITE");
    }
    else if(steamedMilk=="yes"||chocolate=="no"||milkFoam=="yes"||water=="no"||whippedCream=="no"||halfAndHalf=="no"){
        System.out.println("CAPPUCCINO and CAFFE LATTE");
    }    

    else if(steamedMilk=="no"||chocolate=="no"||milkFoam=="no"||water=="yes"||whippedCream=="no"||halfAndHalf=="no"){
        System.out.println("AMERICANO");
    }
    else if(steamedMilk=="yes"||chocolate=="yes"||milkFoam=="no"||water=="no"||whippedCream=="yes"||halfAndHalf=="no"){
        System.out.println("MOCHA");    
    }
    else if(steamedMilk=="no"||chocolate=="no"||milkFoam=="yes"||water=="no"||whippedCream=="no"||halfAndHalf=="yes"){
        System.out.println("BREVE");
    }
    else if(steamedMilk=="no"||chocolate=="no"||milkFoam=="yes"||water=="no"||whippedCream=="no"||halfAndHalf=="no"){
        System.out.println("MACCHIATO");
    }
    else if(steamedMilk=="no"||chocolate=="no"||milkFoam=="NO"||water=="no"||whippedCream=="yes"||halfAndHalf=="yes"){
        System.out.println("CON PANNA");
    }     
}
} 

Aucun commentaire:

Enregistrer un commentaire