I'm making a Character Creator for fun and I seem have run into yet another java problem! I tried googling around for a bit but I didn't seem to find a working solution... I'm trying to use a switch statement for the compiler to output certain information depending on what class (Knight, Archer, Mage) the user chose, but when inputting my code I get error messages
My code so far (cleaned up a bit) is :
String name;
String className;
int attPoints;
System.out.println("Welcome to 'GameName's' Character Creator 2.0!\n");
Thread.sleep(500);
System.out.print("First off, what do you want your characters name to be? \n\nName : ");
name = Scan.nextLine();
Thread.sleep(500);
System.out.print("\nYou are now to be known as "+ name + "!");
System.out.print("\n\n" + name + ", what class do you want to be? ");
System.out.print("\n\nClasses available :\nKnight");
Thread.sleep(1500);
System.out.print("\nMage");
Thread.sleep(300);
System.out.print("\nDruid");
Thread.sleep(300);
System.out.print("\nNinja");
Thread.sleep(300);
System.out.print("\nArcher");
Thread.sleep(300);
System.out.print("\nAdventurer");
Thread.sleep(300);
System.out.print("\nBerserker");
Thread.sleep(300);
System.out.print("\n\nClass : ");
className = Scan.next();
Class userClass = Class.valueOf(className);
Thread.sleep(500);
System.out.println("\nCongratulations! Your class is now : "+ className + "!");
Thread.sleep(500);
// This is where I get an error.
// - Syntax error, insert "enum Identifier" to complete EnumHeaderName
// - Syntax error, insert "EnumBody" to complete BlockStatement
// - Syntax error on token "void", @ expected
public void setClass()
switch (Class) {
case Knight:
System.out.println(" Various lore about knights ");
break;
}
}
I THINK I may be trying to create a class inside another class - but when I tried putting it outside it got another error... Also, I have an int called attPoints, and after I choose a class I want to add 10 to it, but unsure how.
java.langfor your own types; useCharacterClassor something similar instead. Presumably you're using anenum Class, and it looks like the problems are there. (1) Post the code for the enum. (2) Compiler errors specify where the errors are occurring. Post that information.switch, you generally should define methods on the enum and provide the implementations for each value.