Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Why am i getting this error?

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why am i getting this error?

    Iam very new to programming and am trying to make a simple game(for my final) where a user has to pick a path and depending on the path he takes he will either live or die. i get this error
    symbol : variable badPath
    location: class FinalS1
    if (Path == badPath)

    import java.util.Scanner;
    import java.util.Random;
     
    public class FinalS1
    {
    	public static void main (String[] args)
    	{
    	Scanner scan = new Scanner(System.in);
    	int Path;
     
    	System.out.println(" ________         __                            ");
    	System.out.println("|  |  |  |.-----.|  |.----.-----.--------.-----.");
    	System.out.println("|  |  |  ||  -__||  ||  __|  _  |        |  -__|");
    	System.out.println("|________||_____||__||____|_____|__|__|__|_____|");
     
     
    	System.out.println("Press Enter to Start");
    	scan.nextLine();
    	System.out.println("Press Enter to go to the next line"); //Pressing Enter will make it go to next line
    	scan.nextLine();
    	System.out.println("This is an adventure game, don't die!");
    	scan.nextLine();
     
    	System.out.println(" ~~~~~~~~~ ");
    	System.out.println("{ Level 1 }");
    	System.out.println(" ~~~~~~~~~ ");
    	scan.nextLine();
     
    	Level myLevel = new Level();
    	myLevel.badPath();
     
    	System.out.println("Pick the correct path");
    	scan.nextLine();
    	System.out.println("Path 1 or Path 2");
     
    	Path=scan.nextInt();
     
    		if (Path == badPath)
    		System.out.println("lose");
     
    	else 
    		System.out.println("win");
    }}

    import java.util.Random;
     
    public class Level
    {
    	public int Path=1, badPath;
    	Random gen = new Random();
     
    	public int badPath()
    	{
    		badPath = gen.nextInt(0) + 1;
    		return badPath;
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,252
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Why am i getting this error?

    You need to include what type of error it was.

    Note: It's generally a bad idea to have a method and a variable with the same name. It can be confusing to anyone reading the code. Methods should be named as verbs (they do something), variables as nouns, naming the data they hold.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: November 30th, 2013, 05:52 PM
  2. Problems with A* Map Search - GC Overload Error and Null Error
    By puneeth.meruva in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2013, 04:01 PM
  3. Replies: 4
    Last Post: October 15th, 2013, 05:33 AM
  4. Please! Help me to this error "ERROR CANNOT FIND SYMBOL"
    By mharck in forum Object Oriented Programming
    Replies: 8
    Last Post: July 3rd, 2012, 10:20 AM