Results 1 to 2 of 2
Thread: Help with Switch string code
- 07-24-2007, 03:28 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Help with Switch string code
Hello, I have a question involving strings... Ill post the code then the question.
Java Code:switch (jobChoice) { case 'p': System.out.println("You are now a programer!"); setClass("programmer"); programmingStart(); break; case 's': System.out.println("You are now a soldier!"); setClass("soldier"); soldierStart(); break; case 'm': System.out.println("You are now working in a medical field"); setClass("medical"); medicalStart(); break; default: System.out.println("Not a valid choice."); break; }The first code segment I set the classType to whatever the class is, but how do I use it in the class to determine which stats to roll? I've tried .equals a few different ways, as well as ==, maybe I'm messing up how the .equals works?Java Code:public void setClass(String charClass) { classType = charClass; } public void roll() { Random rand = new Random(); if (classType.equals("programmer")) { strength = rand.nextInt(21) + 5; dexterity = rand.nextInt(21) + 5; constitution = rand.nextInt(21) + 5; wisdom = rand.nextInt(21) + 5; knowledge = rand.nextInt(21) + 5; }
Thanks.
- 08-07-2007, 06:00 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
Help with switch color
By Daniel in forum AWT / SwingReplies: 2Last Post: 09-18-2008, 07:54 AM -
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 -
String Code Indentation
By andysh in forum New To JavaReplies: 1Last Post: 12-22-2007, 02:45 AM -
Switch Statemet
By Java Tip in forum Java TipReplies: 0Last Post: 11-30-2007, 09:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks