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 6 of 6

Thread: if-else statement problem! PLEASE help!

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

    Question if-else statement problem! PLEASE help!

    I have a game project due at midnight tonight. I chose to do a choose your own story type game, where the user is given choices and their fate is decided by what they choose to do. Please bear with the story line, I wrote it for my nephews and niece who love Mario Kart. A few of my "else" statements say that there is no "if" statement to match. Everything runs fine if I choose Mario as my character, but not so much when I choose Luigi. I have absolutely NO idea what to do to fix the problem. If anyone has any idea of what I'm doing wrong please write back ASAP! I've been trying to fix this problem for days now, and just thought of posting on a forum today. Thank you all so much for your time and effort.

     
    <import java.util.Scanner;
    public class GameProject {
        public static void main(String[] args) {
    char Character;
    char Drive;
    char Ramp;
    char ramp;
    char drive;
    char ramp2;
    char Direction;
    char Cave;
    char Ramp2;
    char Light;
    char Lane;
    char direction;
    char cave;
    char direction2;
    char Direction2;
    char Cave2;
    char cave2;
    char light;
    char light2;
    char Light2;
    char lane;
    char lane2;
    char Lane2;
     
    Scanner userInput = new Scanner(System.in);
            System.out.println("Mario Kart");
            System.out.println("It was a sunny Saturday morning and all of the Mario "
                    + "Kart characters were getting ready for the big race. Today wasn't "
                    + "just any ordinary race like every other day, it was the Champion Course! "
                    + "The Champion Course was a lot more long, and way more difficult than "
                    + "the other Mario Kart courses. There were a lot of places where the "
                    + "drivers have to choose their own direction, and hope they didn't choose "
                    + "wrong! Today twelve Mario Kart characters are going to compete "
                    + "to determine who the ultimate Mario Kart champion is. The 12 "
                    + "drivers are: Mario, Luigi, Princess Peach, Princess Daisy, Donkey "
                    + "Kong, Diddy Kong, Yoshi, Toad, Wario, Waluigi, Baby Mario, and "
                    + "King Boo. Which character would you like to be?");
            System.out.println("Choices (2) :");
            System.out.println("Press A to race as Mario");
            System.out.println("Press B to race as Luigi");
            Character = userInput.next().charAt(0); 
            if (Character == 'A' || Character == 'a')
            {System.out.println ("You picked Mario! Right now Mario is getting ready "
                    + "to pick out his kart or bike for the race. The rule is that the "
                    + "drivers are only allowed to use the standard vehicles, so what "
                    + "should Mario drive?");
            System.out.println("Choices (2):");
            System.out.println("Press A to drive a kart");
            System.out.println("Press B to drive a bike");
            Drive = userInput.next().charAt(0);
            if (Drive == 'A' || Drive == 'a')
            {System.out.println("You chose to drive a kart. Mario pulls up to the "
                    + "starting line just as the announcer says the race is about to "
                    + "begin. The crowd is cheering, and Mario waves to all of his fans! "
                    + "Hayden and Boo are in the front row smiling, clapping, and cheering "
                    + "for Mario to win the race. They have amazing seats for the race! "
                    + "Mario gets into his kart and the light turns green. All of the "
                    + "drivers take off down the course. The first thing Mario sees is "
                    + "a ramp, but it's located in the middle of the grass and he can't "
                    + "see what is past it. Should Mario use his speed boost to drive "
                    + "onto the grass and use the ramp?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the ramp");
            System.out.println("Press B to keep driving straight");
            Ramp = userInput.next().charAt(0);
            if (Ramp == 'A' || Ramp == 'a')
            {System.out.println("You chose to use the ramp. Mario veers off toward "
                    + "the grass, uses his speed boost, and shoots up into the air. "
                    + "When he's already in the air Mario notices a lake right in "
                    + "front of him. He hears the crowd gasp as he tries to turn his "
                    + "wheel, but it's too late. Mario pushes his ejector seat as his "
                    + "kart sinks into the lake. He floats softly to the ground, safe "
                    + "but sad because he lost the race. Game over!");
            }
            else 
            {System.out.println("You chose to keep driving straight. Good choice, "
                    + "as Mario drives past the ramp he sees a lake in the distance "
                    + "that he would've landed in. Just as Mario thinks he's very lucky "
                    + "to have gone straight, he sees Princess Daisy's kart splash into "
                    + "the water. Now only 11 drivers were left in the race. Up ahead "
                    + "Mario could see a split in the road, he had to choose to go left "
                    + "or right. Which way should Mario go?");
            System.out.println("Choices (2):");
            System.out.println("Press A to turn left");
            System.out.println("Press B to turn right");
            Direction = userInput.next().charAt(0);
            if (Direction == 'A' || Direction == 'a')
            {System.out.println("You chose to turn left. As Mario turns the corner he "
                    + "dodges a banana peel and a green shell thrown by Donkey Kong, who "
                    + "was right in front of him. The green shell shoots past Mario and "
                    + "hits Yoshi's bike. Yoshi's bike flips over and he skids across "
                    + "the grass. Now only 10 players were left in the race. However, "
                    + "Diddy Kong, Toad, and Wario turned right at the split in the "
                    + "road. On the right side of the mountain there were spikes that "
                    + "popped their tires, so those 3 drivers were also out of the "
                    + "race. Only 7 players remained, and as Mario drove over the "
                    + "bridge at the end of the mountain he had another decision to make. "
                    + "He could either use a bouncy mushroom to jump into the cave, or "
                    + "drive the long way around the gorge. What should Mario do?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the bouncy mushroom");
            System.out.println("Press B to drive around the gorge");
            Cave = userInput.next().charAt(0);
            if (Cave == 'A' || Cave == 'a')
            {System.out.println("You chose to use the bouncy mushroom. As Mario shoots "
                    + "into the air and lands on the mushroom he begins to feel nervous. "
                    + "Mario can't see anything in front of him, but he has faith. As he "
                    + "takes off into the air once more he sees the entrance of the cave "
                    + "right in front of him, and takes a breath of relif. Mario lands safely "
                    + "in the chilly cave, but can't see very well. He starts driving very "
                    + "cautiously, and notices there are bats in the distance. Mario hears "
                    + "the echoing of engines coming up fast behind him, so he pulls off "
                    + "the road to the right side and waits. Two drivers flew past Mario so "
                    + "fast that he couldn't even see their faces. They drove right into the "
                    + "bats, and got so distracted that they crashed into eachother. Neither "
                    + "car was moving, and the bats were distracted by the two drivers, so "
                    + "Mario once again began driving through the cave. He could see "
                    + "two lights in the distance: one slightly bigger than the other. "
                    + "Which light should Mario head towards?");
            System.out.println("Choices (2):");
            System.out.println("Press A to drive towards the bigger light");
            System.out.println("Press B to drive towards the smaller light");
            Light = userInput.next().charAt(0);
            if (Light == 'A' || Light == 'a')
            {System.out.println("You chose to drive towards the bigger light. As Mario "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Mario reaches the light and as he drives out he notices "
                    + "that there is no road around him. He drove right off the edge of "
                    + "the cliff! As he's falling downwards towards the river surrounded "
                    + "by rocks, Mario quickly pushes his ejector seat button. He floats "
                    + "up to safety, and watches his kart crash into pieces at the bottom. "
                    + "Game over!");
            }
            else
            {System.out.println("You chose to drive towards the smaller light. As Mario "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Mario reaches the light and as he drives out he sees the "
                    + "finish line in the distance. The race is coming to a finish and "
                    + "all that's left on the course is two lanes in a straight road "
                    + "leading to the ribbon and the trophy at the end. Mario quickly "
                    + "looks around and notices that he is in first place! Mario had been "
                    + "driving in the left lane since he exited the cave, but he had "
                    + "the choice of switching to the right lane before a fence seperated "
                    + "them. Mario could hear his remaining opponents coming up behind him, "
                    + "and he had to make his decision quickly. Should Mario switch lanes or "
                    + "stay where he is?");
            System.out.println("Choices (2):");
            System.out.println("Press A to switch lanes");
            System.out.println("Press B to stay in the same lane");
            Lane = userInput.next().charAt(0);
            if (Lane == 'A' || Lane == 'a')
            {System.out.println("You chose to switch lanes. Mario quickly veers into the "
                    + "right lane, and steps on the gas to fly straight through the finish "
                    + "line. Mario was so close to that first place trophy, he could taste it! "
                    + "Mario was so excited that he didn't notice the banana peel on the road "
                    + "in front of him. Mario ran right over the banana peel and lost "
                    + "control for just one second, but one second was enough. Out of the "
                    + "corner of his eye Mario saw Luigi pass by in the left lane, which "
                    + "was free of banana peels. Just as Mario regained control of his car, "
                    + "and started again for the finish line, Luigi drove through the ribbon. "
                    + "Mario realized he hadn't got first place, but he still had a shot at "
                    + "second, so Mario stepped on the gas pedal and flew through the finish "
                    + "line. Mario was sad that he lost the Champion Course this year, but "
                    + "he was happy for his brother. Mario and Luigi shook hands with each "
                    + "other and all of the other competitors. Even though Mario didn't "
                    + "get first place, he knew that all of the characters were winners "
                    + "because they had such a fun day! Game over!");
            }
            else
            {System.out.println("You chose to stay in the same lane. Mario steps on the "
                    + "gas, he hopes he'll be able to fly right through the finish line. "
                    + "Mario can hear the other drivers on his tail, but he focuses on himself. "
                    + "Mario finally reaches the finish line, drives right through the ribbon, "
                    + "and the crowd goes wild! Mario gets out of his kart and is greeted by "
                    + "Hayden, Boo, and Princess Peach with hugs, high fives, and congratulations! "
                    + "Luigi and the other characters still racing make it through the finish "
                    + "line, and Mario shakes hands with all of the characters. Mario is proud "
                    + "of all of his friends for participating in the race. He knows that even "
                    + "though he got first place, all of the characters were winners because "
                    + "they had such a fun day! Game over!");
            }
            }
            }
            else
            {System.out.println("You chose to drive around the gorge. It takes Mario much "
                    + "longer to find the entrance to the cave, but finally he sees a big black "
                    + "spot on the grey mountain, and he figures this is the entrance. Mario "
                    + "drives full speed toward the entrance, but as he gets close he notices "
                    + "it's just paint on the cave wall. Mario realized that this was a trick "
                    + "entrance, but he was driving so fast that his brakes didn't stop him in "
                    + "time. Mario slammed into the mountain, and his kart was too damaged to "
                    + "continue the race. Game over!");
            }
            }
            else
            {System.out.println("You chose to turn right. As Mario turns the corner he "
                    + "sees a bunch of spikes in the road. He tries to turn around, but "
                    + "there isn't enough time. Mario rides right over the spikes and "
                    + "his tires pop. Mario can't continue the race without pumped up "
                    + "tires. Game over!");
            }
            }
            }
            else 
                    {System.out.println("You chose to drive a bike. Mario pulls up to the "
                    + "starting line just as the announcer says the race is about to "
                    + "begin. The crowd is cheering, and Mario waves to all of his fans! "
                    + "Hayden and Boo are in the front row smiling, clapping, and cheering "
                    + "for Mario to win the race. They have amazing seats for the race! "
                    + "Mario gets onto his bike and and the light turns green. All of the "
                    + "drivers take off down the course. The first thing Mario sees is "
                    + "a ramp, but it's located in the middle of the grass and he can't "
                    + "see what is past it. Should Mario use his speed boost to drive "
                    + "onto the grass and use the ramp?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the ramp");
            System.out.println("Press B to keep driving straight");
            ramp = userInput.next().charAt(0);
            if (ramp == 'A' || ramp == 'a')
            {System.out.println("You chose to use the ramp. Mario veers off toward "
                    + "the grass, uses his speed boost, and shoots up into the air. "
                    + "When he's already in the air Mario notices a lake right in "
                    + "front of him. He hears the crowd gasp as he tries to turn his "
                    + "handle bars, but it's too late. Mario pushes his ejector seat as his "
                    + "bike sinks into the lake. He floats softly to the ground, safe "
                    + "but sad because he lost the race. Game over!");
            }
            else 
            {System.out.println("You chose to keep driving straight. Good choice, "
                    + "as Mario drives past the ramp he sees a lake in the distance "
                    + "that he would've landed in. Just as Mario thinks he's very lucky "
                    + "to have gone straight, he sees Princess Daisy's kart splash into "
                    + "the water. Now only 11 drivers were left in the race. Up ahead "
                    + "Mario could see a split in the road, he had to choose to go left "
                    + "or right. Which way should Mario go?");
            System.out.println("Choices (2):");
            System.out.println("Press A to turn left");
            System.out.println("Press B to turn right");
            direction = userInput.next().charAt(0);
            if (direction == 'A' || direction == 'a')
            {System.out.println("You chose to turn left. As Mario turns the corner he "
                    + "dodges a banana peel and a green shell thrown by Donkey Kong, who "
                    + "was right in front of him. The green shell shoots past Mario and "
                    + "hits Yoshi's bike. Yoshi's bike flips over and he skids across "
                    + "the grass. Now only 10 players were left in the race. However, "
                    + "Diddy Kong, Toad, and Wario turned right at the split in the "
                    + "road. On the right side of the mountain there were spikes that "
                    + "popped their tires, so those 3 drivers were also out of the "
                    + "race. Only 7 players remained, and as Mario drove over the "
                    + "bridge at the end of the mountain he had another decision to make. "
                    + "He could either use a bouncy mushroom to jump into the cave, or "
                    + "drive the long way around the gorge. What should Mario do?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the bouncy mushroom");
            System.out.println("Press B to drive around the gorge");
            cave = userInput.next().charAt(0);
            if (cave == 'A' || cave == 'a')
            {System.out.println("You chose to use the bouncy mushroom. As Mario shoots "
                    + "into the air and lands on the mushroom he begins to feel nervous. "
                    + "Mario can't see anything in front of him, but he has faith. As he "
                    + "takes off into the air once more he sees the entrance of the cave "
                    + "right in front of him, and takes a breath of relif. Mario lands safely "
                    + "in the chilly cave, but can't see very well. He starts driving very "
                    + "cautiously, and notices there are bats in the distance. Mario hears "
                    + "the echoing of engines coming up fast behind him, so he pulls off "
                    + "the road to the right side and waits. Two drivers flew past Mario so "
                    + "fast that he couldn't even see their faces. They drove right into the "
                    + "bats, and got so distracted that they crashed into eachother. Neither "
                    + "car was moving, and the bats were distracted by the two drivers, so "
                    + "Mario once again began driving through the cave. He could see "
                    + "two lights in the distance: one slightly bigger than the other. "
                    + "Which light should Mario head towards?");
            System.out.println("Choices (2):");
            System.out.println("Press A to drive towards the bigger light");
            System.out.println("Press B to drive towards the smaller light");
            light = userInput.next().charAt(0);
            if (light == 'A' || light == 'a')
            {System.out.println("You chose to drive towards the bigger light. As Mario "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Mario reaches the light and as he drives out he notices "
                    + "that there is no road around him. He drove right off the edge of "
                    + "the cliff! As he's falling downwards towards the river surrounded "
                    + "by rocks, Mario quickly pushes his ejector seat button. He floats "
                    + "up to safety, and watches his bike crash into pieces at the bottom. "
                    + "Game over!");
            }
            else
            {System.out.println("You chose to drive towards the smaller light. As Mario "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Mario reaches the light and as he drives out he sees the "
                    + "finish line in the distance. The race is coming to a finish and "
                    + "all that's left on the course is two lanes in a straight road "
                    + "leading to the ribbon and the trophy at the end. Mario quickly "
                    + "looks around and notices that he is in first place! Mario had been "
                    + "driving in the left lane since he exited the cave, but he had "
                    + "the choice of switching to the right lane before a fence seperated "
                    + "them. Mario could hear his remaining opponents coming up behind him, "
                    + "and he had to make his decision quickly. Should Mario switch lanes or "
                    + "stay where he is?");
            System.out.println("Choices (2):");
            System.out.println("Press A to switch lanes");
            System.out.println("Press B to stay in the same lane");
            lane = userInput.next().charAt(0);
            if (lane == 'A' || lane == 'a')
            {System.out.println("You chose to switch lanes. Mario quickly veers into the "
                    + "right lane, and steps on the gas to fly straight through the finish "
                    + "line. Mario was so close to that first place trophy, he could taste it! "
                    + "Mario was so excited that he didn't notice the banana peel on the road "
                    + "in front of him. Mario ran right over the banana peel and lost "
                    + "control for just one second, but one second was enough. Out of the "
                    + "corner of his eye Mario saw Luigi pass by in the left lane, which "
                    + "was free of banana peels. Just as Mario regained control of his car, "
                    + "and started again for the finish line, Luigi drove through the ribbon. "
                    + "Mario realized he hadn't got first place, but he still had a shot at "
                    + "second, so Mario stepped on the gas pedal and flew through the finish "
                    + "line. Mario was sad that he lost the Champion Course this year, but "
                    + "he was happy for his brother. Mario and Luigi shook hands with each "
                    + "other and all of the other competitors. Even though Mario didn't "
                    + "get first place, he knew that all of the characters were winners "
                    + "because they had such a fun day! Game over!");
            }
            else
            {System.out.println("You chose to stay in the same lane. Mario steps on the "
                    + "gas, he hopes he'll be able to fly right through the finish line. "
                    + "Mario can hear the other drivers on his tail, but he focuses on himself. "
                    + "Mario finally reaches the finish line, drives right through the ribbon, "
                    + "and the crowd goes wild! Mario gets off of his bike and is greeted by "
                    + "Hayden, Boo, and Princess Peach with hugs, high fives, and congratulations! "
                    + "Luigi and the other characters still racing make it through the finish "
                    + "line, and Mario shakes hands with all of the characters. Mario is proud "
                    + "of all of his friends for participating in the race. He knows that even "
                    + "though he got first place, all of the characters were winners because "
                    + "they had such a fun day! Game over!");
            }
            }
            }
            }
                    }
            }
                    }
            else
            {
                System.out.println("You picked Luigi! Right now Luigi is getting ready "
                        + "to pick out his kart or bike for the race. What should Luigi "
                        + "drive?");
                 System.out.println("Choices (2):");
                 System.out.println("Press A to drive a kart");
                 System.out.println("Press B to drive a bike");
                 drive = userInput.next().charAt(0);
                 if (drive == 'A' || drive == 'a')
            {System.out.println("You chose to drive a kart. Luigi pulls up to the "
                    + "starting line just as the announcer says the race is about to "
                    + "begin. The crowd is cheering, and Luigi waves to all of his fans! "
                    + "Cam and Kenna are in the front row smiling, clapping, and cheering "
                    + "for Luigi to win the race. They have amazing seats for the race! "
                    + "Luigi gets into his kart and the light turns green. All of the "
                    + "drivers take off down the course. The first thing Luigi sees is "
                    + "a ramp, but it's located in the middle of the grass and he can't "
                    + "see what is past it. Should Luigi use his speed boost to drive "
                    + "onto the grass and use the ramp?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the ramp");
            System.out.println("Press B to keep driving straight");
            ramp2 = userInput.next().charAt(0);
            if (ramp2 == 'A' || ramp2 == 'a')
            {System.out.println("You chose to use the ramp. Luigi veers off toward "
                    + "the grass, uses his speed boost, and shoots up into the air. "
                    + "When he's already in the air Luigi notices a lake right in "
                    + "front of him. He hears the crowd gasp as he tries to turn his "
                    + "wheel, but it's too late. Luigi pushes his ejector seat as his "
                    + "kart sinks into the lake. He floats softly to the ground, safe "
                    + "but sad because he lost the race. Game over!");
            }
            else 
            {System.out.println("You chose to keep driving straight. Good choice, "
                    + "as Luigi drives past the ramp he sees a lake in the distance "
                    + "that he would've landed in. Just as Luigi thinks he's very lucky "
                    + "to have gone straight, he sees Princess Daisy's kart splash into "
                    + "the water. Now only 11 drivers were left in the race. Up ahead "
                    + "Luigi could see a split in the road, he had to choose to go left "
                    + "or right. Which way should Luigi go?");
            System.out.println("Choices (2):");
            System.out.println("Press A to turn left");
            System.out.println("Press B to turn right");
            direction2 = userInput.next().charAt(0);
            if (direction2 == 'A' || direction2 == 'a')
            {System.out.println("You chose to turn left. As Luigi turns the corner he "
                    + "dodges a banana peel and a green shell thrown by Donkey Kong, who "
                    + "was right in front of him. The green shell shoots past Luigi and "
                    + "hits Yoshi's bike. Yoshi's bike flips over and he skids across "
                    + "the grass. Now only 10 players were left in the race. However, "
                    + "Diddy Kong, Toad, and Wario turned right at the split in the "
                    + "road. On the right side of the mountain there were spikes that "
                    + "popped their tires, so those 3 drivers were also out of the "
                    + "race. Only 7 players remained, and as Luigi drove over the "
                    + "bridge at the end of the mountain he had another decision to make. "
                    + "He could either use a bouncy mushroom to jump into the cave, or "
                    + "drive the long way around the gorge. What should Luigi do?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the bouncy mushroom");
            System.out.println("Press B to drive around the gorge");
            cave2 = userInput.next().charAt(0);
            if (cave2 == 'A' || cave2 == 'a')
            {System.out.println("You chose to use the bouncy mushroom. As Luigi shoots "
                    + "into the air and lands on the mushroom he begins to feel nervous. "
                    + "Luigi can't see anything in front of him, but he has faith. As he "
                    + "takes off into the air once more he sees the entrance of the cave "
                    + "right in front of him, and takes a breath of relif. Luigi lands safely "
                    + "in the chilly cave, but can't see very well. He starts driving very "
                    + "cautiously, and notices there are bats in the distance. Luigi hears "
                    + "the echoing of engines coming up fast behind him, so he pulls off "
                    + "the road to the right side and waits. Two drivers flew past Luigi so "
                    + "fast that he couldn't even see their faces. They drove right into the "
                    + "bats, and got so distracted that they crashed into eachother. Neither "
                    + "car was moving, and the bats were distracted by the two drivers, so "
                    + "Luigi once again began driving through the cave. He could see "
                    + "two lights in the distance: one slightly bigger than the other. "
                    + "Which light should Luigi head towards?");
            System.out.println("Choices (2):");
            System.out.println("Press A to drive towards the bigger light");
            System.out.println("Press B to drive towards the smaller light");
            light2 = userInput.next().charAt(0);
            if (light2 == 'A' || light2 == 'a')
            {System.out.println("You chose to drive towards the bigger light. As Luigi "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Luigi reaches the light and as he drives out he notices "
                    + "that there is no road around him. He drove right off the edge of "
                    + "the cliff! As he's falling downwards towards the river surrounded "
                    + "by rocks, Luigi quickly pushes his ejector seat button. He floats "
                    + "up to safety, and watches his kart crash into pieces at the bottom. "
                    + "Game over!");
            }
            else
            {System.out.println("You chose to drive towards the smaller light. As Luigi "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Luigi reaches the light and as he drives out he sees the "
                    + "finish line in the distance. The race is coming to a finish and "
                    + "all that's left on the course is two lanes in a straight road "
                    + "leading to the ribbon and the trophy at the end. Luigi quickly "
                    + "looks around and notices that he is in first place! Luigi had been "
                    + "driving in the left lane since he exited the cave, but he had "
                    + "the choice of switching to the right lane before a fence seperated "
                    + "them. Luigi could hear his remaining opponents coming up behind him, "
                    + "and he had to make his decision quickly. Should Luigi switch lanes or "
                    + "stay where he is?");
            System.out.println("Choices (2):");
            System.out.println("Press A to switch lanes");
            System.out.println("Press B to stay in the same lane");
            lane2 = userInput.next().charAt(0);
            if (lane2 == 'A' || lane2 == 'a')
            {System.out.println("You chose to switch lanes. Luigi quickly veers into the "
                    + "right lane, and steps on the gas to fly straight through the finish "
                    + "line. Luigi was so close to that first place trophy, he could taste it! "
                    + "Luigi was so excited that he didn't notice the banana peel on the road "
                    + "in front of him. Luigi ran right over the banana peel and lost "
                    + "control for just one second, but one second was enough. Out of the "
                    + "corner of his eye Luigi saw Mario pass by in the left lane, which "
                    + "was free of banana peels. Just as Luigi regained control of his kart, "
                    + "and started again for the finish line, Mario drove through the ribbon. "
                    + "Luigi realized he hadn't got first place, but he still had a shot at "
                    + "second, so Luigi stepped on the gas pedal and flew through the finish "
                    + "line. Luigi was sad that he lost the Champion Course this year, but "
                    + "he was happy for his brother. Luigi and Mario shook hands with each "
                    + "other and all of the other competitors. Even though Luigi didn't "
                    + "get first place, he knew that all of the characters were winners "
                    + "because they had such a fun day! Game over!");
            }
            else
            {System.out.println("You chose to stay in the same lane. Luigi steps on the "
                    + "gas, he hopes he'll be able to fly right through the finish line. "
                    + "Luigi can hear the other drivers on his tail, but he focuses on himself. "
                    + "Luigi finally reaches the finish line, drives right through the ribbon, "
                    + "and the crowd goes wild! Luigi gets out of his car and is greeted by "
                    + "Cam, Mackenna, and Princess Daisy with hugs, high fives, and congratulations! "
                    + "Mario and the other characters still racing make it through the finish "
                    + "line, and Luigi shakes hands with all of the characters. Luigi is proud "
                    + "of all of his friends for participating in the race. He knows that even "
                    + "though he got first place, all of the characters were winners because "
                    + "they had such a fun day! Game over!");
            }
            }
            }
            }
            }
            else 
                    {System.out.println("You chose to drive a bike. Luigi pulls up to the "
                    + "starting line just as the announcer says the race is about to "
                    + "begin. The crowd is cheering, and Luigi waves to all of his fans! "
                    + "Cam and Kenna are in the front row smiling, clapping, and cheering "
                    + "for Luigi to win the race. They have amazing seats for the race! "
                    + "Luigi gets onto his bike and and the light turns green. All of the "
                    + "drivers take off down the course. The first thing Luigi sees is "
                    + "a ramp, but it's located in the middle of the grass and he can't "
                    + "see what is past it. Should Luigi use his speed boost to drive "
                    + "onto the grass and use the ramp?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the ramp");
            System.out.println("Press B to keep driving straight");
            Ramp2 = userInput.next().charAt(0);
            if (Ramp2 == 'A' || Ramp2 == 'a')
            {System.out.println("You chose to use the ramp. Luigi veers off toward "
                    + "the grass, uses his speed boost, and shoots up into the air. "
                    + "When he's already in the air Luigi notices a lake right in "
                    + "front of him. He hears the crowd gasp as he tries to turn his "
                    + "handle bars, but it's too late. Luigi pushes his ejector seat as his "
                    + "bike sinks into the lake. He floats softly to the ground, safe "
                    + "but sad because he lost the race. Game over!");
            }
            else 
            {System.out.println("You chose to keep driving straight. Good choice, "
                    + "as Luigi drives past the ramp he sees a lake in the distance "
                    + "that he would've landed in. Just as Luigi thinks he's very lucky "
                    + "to have gone straight, he sees Princess Peach's kart splash into "
                    + "the water. Now only 11 drivers were left in the race. Up ahead "
                    + "Luigi could see a split in the road, he had to choose to go left "
                    + "or right. Which way should Luigi go?");
            System.out.println("Choices (2):");
            System.out.println("Press A to turn left");
            System.out.println("Press B to turn right");
            Direction2 = userInput.next().charAt(0);
            if (Direction2 == 'A' || Direction2 == 'a')
            {System.out.println("You chose to turn left. As Luigi turns the corner he "
                    + "dodges a banana peel and a green shell thrown by Donkey Kong, who "
                    + "was right in front of him. The green shell shoots past Luigi and "
                    + "hits Yoshi's bike. Yoshi's bike flips over and he skids across "
                    + "the grass. Now only 10 players were left in the race. However, "
                    + "Diddy Kong, Toad, and Wario turned right at the split in the "
                    + "road. On the right side of the mountain there were spikes that "
                    + "popped their tires, so those 3 drivers were also out of the "
                    + "race. Only 7 players remained, and as Luigi drove over the "
                    + "bridge at the end of the mountain he had another decision to make. "
                    + "He could either use a bouncy mushroom to jump into the cave, or "
                    + "drive the long way around the gorge. What should Luigi do?");
            System.out.println("Choices (2):");
            System.out.println("Press A to use the bouncy mushroom");
            System.out.println("Press B to drive around the gorge");
            Cave2 = userInput.next().charAt(0);
            if (Cave2 == 'A' || Cave2 == 'a')
            {System.out.println("You chose to use the bouncy mushroom. As Luigi shoots "
                    + "into the air and lands on the mushroom he begins to feel nervous. "
                    + "Luigi can't see anything in front of him, but he has faith. As he "
                    + "takes off into the air once more he sees the entrance of the cave "
                    + "right in front of him, and takes a breath of relif. Luigi lands safely "
                    + "in the chilly cave, but can't see very well. He starts driving very "
                    + "cautiously, and notices there are bats in the distance. Luigi hears "
                    + "the echoing of engines coming up fast behind him, so he pulls off "
                    + "the road to the right side and waits. Two drivers flew past Luigi so "
                    + "fast that he couldn't even see their faces. They drove right into the "
                    + "bats, and got so distracted that they crashed into eachother. Neither "
                    + "car was moving, and the bats were distracted by the two drivers, so "
                    + "Luigi once again began driving through the cave. He could see "
                    + "two lights in the distance: one slightly bigger than the other. "
                    + "Which light should Luigi head towards?");
            System.out.println("Choices (2):");
            System.out.println("Press A to drive towards the bigger light");
            System.out.println("Press B to drive towards the smaller light");
            Light2 = userInput.next().charAt(0);
            if (Light2 == 'A' || Light2 == 'a')
            {System.out.println("You chose to drive towards the bigger light. As Luigi "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Luigi reaches the light and as he drives out he notices "
                    + "that there is no road around him. He drove right off the edge of "
                    + "the cliff! As he's falling downwards towards the river surrounded "
                    + "by rocks, Luigi quickly pushes his ejector seat button. He floats "
                    + "up to safety, and watches his bike crash into pieces at the bottom. "
                    + "Game over!");
            }
            else
            {System.out.println("You chose to drive towards the smaller light. As Luigi "
                    + "gets closer to the light it gets bigger, and bigger. He doesn't see "
                    + "anything beyond the light, and he hopes nothing bad is about to "
                    + "happen. Luigi reaches the light and as he drives out he sees the "
                    + "finish line in the distance. The race is coming to a finish and "
                    + "all that's left on the course is two lanes in a straight road "
                    + "leading to the ribbon and the trophy at the end. Luigi quickly "
                    + "looks around and notices that he is in first place! Luigi had been "
                    + "driving in the left lane since he exited the cave, but he had "
                    + "the choice of switching to the right lane before a fence seperated "
                    + "them. Luigi could hear his remaining opponents coming up behind him, "
                    + "and he had to make his decision quickly. Should Luigi switch lanes or "
                    + "stay where he is?");
            System.out.println("Choices (2):");
            System.out.println("Press A to switch lanes");
            System.out.println("Press B to stay in the same lane");
            Lane2 = userInput.next().charAt(0);
            if (Lane2 == 'A' || Lane2 == 'a')
            {System.out.println("You chose to switch lanes. Luigi quickly veers into the "
                    + "right lane, and steps on the gas to fly straight through the finish "
                    + "line. Luigi was so close to that first place trophy, he could taste it! "
                    + "Luigi was so excited that he didn't notice the banana peel on the road "
                    + "in front of him. Luigi ran right over the banana peel and lost "
                    + "control for just one second, but one second was enough. Out of the "
                    + "corner of his eye Luigi saw Mario pass by in the left lane, which "
                    + "was free of banana peels. Just as Luigi regained control of his car, "
                    + "and started again for the finish line, Mario drove through the ribbon. "
                    + "Luigi realized he hadn't got first place, but he still had a shot at "
                    + "second, so Luigi stepped on the gas pedal and flew through the finish "
                    + "line. Luigi was sad that he lost the Champion Course this year, but "
                    + "he was happy for his brother. Luigi and Mario shook hands with each "
                    + "other and all of the other competitors. Even though Luigi didn't "
                    + "get first place, he knew that all of the characters were winners "
                    + "because they had such a fun day! Game over!");
            }
            else
            {System.out.println("You chose to stay in the same lane. Luigi steps on the "
                    + "gas, he hopes he'll be able to fly right through the finish line. "
                    + "Luigi can hear the other drivers on his tail, but he focuses on himself. "
                    + "Luigi finally reaches the finish line, drives right through the ribbon, "
                    + "and the crowd goes wild! Luigi gets off of his bike and is greeted by "
                    + "Cam, Kenna, and Princess Daisy with hugs, high fives, and congratulations! "
                    + "Mario and the other characters still racing make it through the finish "
                    + "line, and Luigi shakes hands with all of the characters. Luigi is proud "
                    + "of all of his friends for participating in the race. He knows that even "
                    + "though he got first place, all of the characters were winners because "
                    + "they had such a fun day! Game over!");
            }
            }
            }
            }
                 }
     
            }
        }
    }>


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

    Default Re: if-else statement problem! PLEASE help!

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    It's very hard to read the posted code to check for syntax errors.

    --- Update ---

    A few of my "else" statements say that there is no "if" statement to match.
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: if-else statement problem! PLEASE help!

    I was wondering how I could preserve the format on the forum. I'm just so new to all of this, it's so confusing! Thank you so much for the information!!

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

    Default Re: if-else statement problem! PLEASE help!

    There is a problem with the formatting. The } should be directly inline below the start of the statement/line with the pairing {. I see many } that are all in the same column making it very hard to read and understand the code.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: if-else statement problem! PLEASE help!

    The error reads: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - 'else' without 'if' at gameproject.GameProject.main(GameProject.java:511)

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

    Default Re: if-else statement problem! PLEASE help!

    The code is impossible to read and understand the way it is formatted. See post#4

    The statements would be easier to see if all of the Strings being displayed were defined at the beginning of the program and the variables used in println() statements in the code. The bulky Strings in the code makes it hard to read.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. HELP: If-Else Statement
    By JennyDang in forum What's Wrong With My Code?
    Replies: 14
    Last Post: March 19th, 2013, 09:12 PM
  2. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 04:19 PM
  3. Replacing an If statement with a Switch statement
    By logi in forum Loops & Control Statements
    Replies: 9
    Last Post: February 4th, 2013, 12:21 AM
  4. [SOLVED] Coin Loop Selective Print Statement Problem
    By sternfox in forum Loops & Control Statements
    Replies: 1
    Last Post: January 30th, 2013, 12:30 AM
  5. Replies: 2
    Last Post: November 7th, 2012, 03:54 AM

Tags for this Thread