I am super new to java so sorry if this is an easy answer. I have to write a code for class that would be used in a smart home type system. Right now i am having a problem with the stopping music command. When i respond Stop music when I run the code, nothing happens. Everything else works. I tried doing if else but then it gives me an error that says syntax error on token else while expected. While what?? I have no clue what i'm doing but here is the code I have so far.
import java.util.Scanner;
public class SmartHome {
public static void main(String[] args) {
double temperature;
String genre;
Scanner console = new Scanner (System.in);
System.out.println("Welcome Home! What would you like to do?");
while (true) {
String command= console.nextLine();
if (command.contentEquals("Change temperature")) {
System.out.println("What temperature would you like?");
temperature=console.nextDouble();
System.out.print("The temperature is now: ");
System.out.println(temperature);
}
while(true){
String input=console.nextLine();
if (input.contentEquals("Play music")) {
System.out.println("What genre would you like?");
genre=console.nextLine();
System.out.print("Playing... ");
System.out.println(genre);
while(input.contentEquals("Stop music"));
System.out.println("Stopping music");
}
if (command.contentEquals("Close system")) {
System.out.println("Shutting down");
console.close();
break; //end the system and stop the loop
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire