Hi,
I have come across this question during my school assignment, and would appreciate some help since this is a new topic for me, I have provided the code I have written so far at the bottom. Basically I'm trying to name my 'cases' so a book can be entered rather than a number as in conjunction with switch cases.
1. Switch to Philip K Dick books
Code:
Program Names : DickBooks.java
Example Input/Output:
A A Scanner Darkly
V Valis
O Our Friends From Frolix 8
U Ubik
D Do Androids Dream of Electric Sheep?
Choose a novel from menu above:
u
You chose "Ubik"
This is a main/driver class.
Use a switch statement to pick a novel by entering the correct character.
• Allow the user to enter upper or lower case.
If the novel is not on the list the program should output this exact string including a newline on the end:
Code:
That novel is not on the list
***MY CODE***
Code:
package assignment3;
import java.util.Scanner;
public class DickBooks {
public static void main(String[] args) {
int novel;
Scanner daniel = new Scanner(System.in);
System.out.print("Choose a novel from menu above:");
novel = 1;
System.out.println("You chose\n" + novel);
switch (novel) {
case 1:
System.out.println("A Scanner Darkly");
break;
case 2:
System.out.println("Valis");
break;
case 3:
System.out.println("Our Friends From Frolix 8");
break;
case 4:
System.out.println("Ubik");
break;
case 5:
System.out.println("Do Androids Dream of Electric Sheep?");
break;
default:
System.out.println("That novel is not on the list");
System.out.println(scan.nextLine());
System.out.println("Choose a novel from menu above:");
}
}
}