hi i'm working on a program using all if else statements. I think i've lost myself in all ifs and elses and i need your guys help! It was working fine until i added some new if elses in the middle of the code heres what it looks like

import java.util.Scanner;
public class WoW
{
public static void main(String[] args)
{
String classname, faction, class, spec;
Scanner inputDevice = new Scanner(System.in);
System.out.println("");
System.out.println("Welcome");
System.out.println("");
System.out.println("This program will help you decide which World of Warcraft");
System.out.println("faction and class is best for you.");
System.out.println("");
System.out.println("Please enter a faction, horde or alliance.");
faction = inputDevice.nextLine();
if(faction.equalsIgnoreCase("horde"))
{
System.out.println("");
System.out.println("You have chosen the horde.");
System.out.println("");
System.out.println("There are 9 different character classes to choose from");
System.out.println("A hunter, warrior, warlock, druid, paladin, mage, shaman, and priest.");
while (faction.equalsIgnoreCase("horde"))
{
System.out.println("");
System.out.println("Please enter a WoW class now.");
classname = inputDevice.nextLine();
if(classname.equalsIgnoreCase("rogue"))
{
System.out.println("");
System.out.println("A rogue uses stealth and daggers to destroy it's opponent.");
System.out.println("");
System.out.println("Are you sure you want to choose a rogue? Type yes or no");
class = inputDevice.nextLine();
if(class.equalsIgnoreCase("yes"))
{
System.out.println("");
System.out.println("A rogue has three different talent trees, Assassination, Combat, and Subtlety.");
System.out.println("Please choose one of the three specs");
spec = inputDevice.nextLine();
if(spec.equalsIgnoreCase("assassination"))
{
System.out.println("Assassination focuses most when a rogue first breaks his stealth");
System.out.println("He is most lethal when first entering battle");
}
else if(spec.equalsIgnoreCase("combat"))
{
System.out.println("Combat makes the rogue lethal fighting without stealthing");
}
else if(spec.equalsIgnoreCase("subtlety"))
{
System.out.println("Subtlety allows the rogue to go to and from stealth throughout a battle");
System.out.println("Making this the primary talent tree for stealth");
}
else
{
System.out.println("Invalid Entry");
}
}
else
{
System.out.println("You typed no");
}
}

this is just teh beginning of the code but its where the error is located im sure.
let me know if you see the problem i'm so lost ! :(

Recommended Answers

All 3 Replies

And now you can see why blocks are indented. Each nested level should be indented from its parent.

Format the code and you'll probably find the problem much easier when you can see the logical hierarchy.

What he said. Between every { and } tab all lines 1 tab inward.

Also you should note that on line 34 you will get an error because you can't call a variable "class" since the word "class" is a reserved Java word.

commented: Good catch - he might get it before then, since I doubt you can declare a variable named class. +4

what you also can do, is put the factions and such into arrays of Strings, determine the location for each in the array, and use that to write a Switch-case statement.
not necessary more efficiƫnt, but easier to read if there are a lot of options

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.