View Single Post
  #1 (permalink)  
Old 07-24-2007, 05:28 PM
toby toby is offline
Member
 
Join Date: Jul 2007
Posts: 40
toby is on a distinguished road
Help with Switch string code
Hello, I have a question involving strings... Ill post the code then the question.
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; }
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; }
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?
Thanks.
Reply With Quote
Sponsored Links