Results 1 to 2 of 2
Thread: Naming a Switch Statement? Help!
- 03-24-2011, 03:05 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 16
- Rep Power
- 0
Naming a Switch Statement? Help!
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
This is a main/driver class.Java 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"
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:
***MY CODE***Java Code:That novel is not on the list
Java 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:"); } } }
- 03-24-2011, 03:34 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,447
- Rep Power
- 16
Similar Threads
-
help with switch statement
By java__beginner in forum New To JavaReplies: 4Last Post: 03-19-2009, 02:22 PM -
Demonstration of the switch statement
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM -
Method in a Switch Statement
By cart1443 in forum New To JavaReplies: 6Last Post: 03-14-2008, 03:48 AM -
Switch Statement Help
By bluegreen7hi in forum New To JavaReplies: 6Last Post: 02-06-2008, 05:16 AM -
Help with gigantamous switch statement
By trill in forum New To JavaReplies: 2Last Post: 08-06-2007, 08:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks