Im writing a program that informs the user that there is a grand piano and gives them the option to play it, however, once the user chooses y for yes it asks the question what song do they want to play however, prints the response to the first song, rather than allowing the user to choose in order to prompt the different responses based on user's choice.
Below is the code, which compiles, however does not work the way I'm intending:
import java.util.*;
public class MyPiano {
private static final String m = null;
private static final String b = null;
private static final String c = null;
private static final String f = null;
private static final String r = null;
private static final String d = null;
//Initialize class variables.
private int numOfKeys;
private String pianoMake;
private String pianoModel;
private boolean tuned;
//A constructor that has specific variables assigned to it.
public MyPiano (int numOfKeys, String pianoMake, String pianoModel, boolean tuned) {
this.numOfKeys = numOfKeys;
this.pianoMake = pianoMake;
this.pianoModel = pianoModel;
this.tuned = tuned;
}
//Created the output that will be displayed to the user.
public String toString() {
return "There is a beautiful " + numOfKeys + " key " + pianoMake + ", " + pianoModel + " in the living room." +
"\nIs it tuned?: " + tuned;
}
public static void main(String args[]) {
//Create an instance of household item method.
MyPiano piano = new MyPiano (88, "Steinway & Sons", "Model M studio grand", true);
//Output the status of the household item.
System.out.println(piano.toString());
Scanner input = new Scanner(System.in);
char letsPlayASong;
System.out.println("Would you like to take a stab at playing a song on the piano? Press Y or y for yes and N or n for no.");
char a = input.next().trim().charAt(0);
if(a == 'Y' || a == 'y') {
//change speed using switch statement
System.out.print("Which song would you like to play?(Beethoven's Moonlight Sonata, Beethoven's Fur Elise, or Chopin's March Funebre): Type m for Moonlight Sonata, f for Fur Elise, or r for March Funebre.");
if(b == m) {
System.out.println("This song is played in C# minor and the first three notes are: G#, C#, and E");
char b = input.next().trim().charAt(0);
} else if(c == f) {
System.out.println("This song was written in A minor with the first two notes being E and D#");
char c = input.next().trim().charAt(0);
} else {
if(d == r) {
System.out.println("This classic, otherwise known as The Funeral March, is to be played in Bb minor, however it can be very tricky!");
char d = input.next().trim().charAt(0);
}
}
} else {
if (a == 'N' || a == 'n'); {
System.exit(0);
}
}
}
}