Reputation: 153
I am trying to create a simple program that outputs the lyrics of a song when the specified number is inputted. The problem is that my second case will not output, but only outputs the first case. When I try to output the second case, it still outputs the first. Regardless if I make two while statement or not, this still happens. Can someone help me fix my code?
Here it is:
import java.util.Scanner;
public class Lyrics {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
int one, two, uone, utwo;
one = 1;
two = 2;
System.out.println("Welcome to the Lyrics Finder!");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
uone = input.nextInt();
utwo = input.nextInt();
switch (one){
case 1:
//code goes here for option 1
System.out.println("");
System.out.println("Thank For The Memories - Fall Out Boy Lyrics");
System.out.println(" == ");
System.out.println("I'm gonna make it bend and break");
System.out.println("Say a prayer but let the good times roll");
System.out.println("In case God doesn't show");
System.out.println("(Let the good times roll, let the good times roll)");
System.out.println("And I want these words to make things right");
System.out.println("But it's the wrongs that make the words come to life");
System.out.println("Who does he think he is?");
System.out.println("Who does he think he is?");
System.out.println("Better put your fingers back to the keys");
//continue song here
break;
case 2:
//retype all code her for it to reset
System.out.println("");
System.out.println("Take Me To Church - Hozier");
System.out.println(" == ");
System.out.println("My lover's got humour, She's the giggle at a funeral");
System.out.println("Knows everybody's disapproval, I should've worshipped her sooner");
System.out.println("If the heavens ever did speak, She's the last true mouthpiece");
System.out.println("Every Sunday's getting more bleak, A fresh poison each week");
System.out.println("We were born sick you heard them say it");
System.out.println("My church offers no absolutes, She tells me Worship in the bedroom");
break;
}
while (uone == one){
System.out.println("");
System.out.println("<-=LYRICS ABOVE=->");
System.out.println("<-=OPTIONS=->");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
uone = input.nextInt();
utwo = input.nextInt();
switch (one){
case 1:
//code goes here for option 1
System.out.println("");
System.out.println("Thank For The Memories - Fall Out Boy Lyrics");
System.out.println(" == ");
System.out.println("I'm gonna make it bend and break");
System.out.println("Say a prayer but let the good times roll");
System.out.println("In case God doesn't show");
System.out.println("(Let the good times roll, let the good times roll)");
System.out.println("And I want these words to make things right");
System.out.println("But it's the wrongs that make the words come to life");
System.out.println("Who does he think he is?");
System.out.println("Who does he think he is?");
System.out.println("Better put your fingers back to the keys");
//continue song here
break;
case 2:
//retype all code her for it to reset
System.out.println("");
System.out.println("Take Me To Church - Hozier");
System.out.println(" == ");
System.out.println("My lover's got humour, She's the giggle at a funeral");
System.out.println("Knows everybody's disapproval, I should've worshipped her sooner");
System.out.println("If the heavens ever did speak, She's the last true mouthpiece");
System.out.println("Every Sunday's getting more bleak, A fresh poison each week");
System.out.println("We were born sick you heard them say it");
System.out.println("My church offers no absolutes, She tells me Worship in the bedroom");
break;
}
}
}
}
When the user types the number one, this should be outputted:
System.out.println("");
System.out.println("Thank For The Memories - Fall Out Boy Lyrics");
System.out.println(" == ");
System.out.println("I'm gonna make it bend and break");
System.out.println("Say a prayer but let the good times roll");
System.out.println("In case God doesn't show");
System.out.println("(Let the good times roll, let the good times roll)");
System.out.println("And I want these words to make things right");
System.out.println("But it's the wrongs that make the words come to life");
System.out.println("Who does he think he is?");
System.out.println("Who does he think he is?");
System.out.println("Better put your fingers back to the keys");
//continue song here
break;
while (uone == one){
System.out.println("");
System.out.println("<-=LYRICS ABOVE=->");
System.out.println("<-=OPTIONS=->");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
When the user types the number 2, this should be outputted:
System.out.println("");
System.out.println("Take Me To Church - Hozier");
System.out.println(" == ");
System.out.println("My lover's got humour, She's the giggle at a funeral");
System.out.println("Knows everybody's disapproval, I should've worshipped her sooner");
System.out.println("If the heavens ever did speak, She's the last true mouthpiece");
System.out.println("Every Sunday's getting more bleak, A fresh poison each week");
System.out.println("We were born sick you heard them say it");
System.out.println("My church offers no absolutes, She tells me Worship in the bedroom");
break;
while (uone == one){
System.out.println("");
System.out.println("<-=LYRICS ABOVE=->");
System.out.println("<-=OPTIONS=->");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
Please note that I am very new to coding, so please try to explain the best that you can. If not, I still may be able to understand, but regardless, please briefly explain your solution.
Upvotes: 0
Views: 65
Reputation: 1192
Change
uone = input.nextInt();
utwo = input.nextInt();
switch (one){
To
int choice = input.nextInt();
switch (choice)
Upvotes: 2