Jump to content

Java Help: Beginner Problem with putting if statements in order.

Hi, another newbie Java question again. Simple question unlike before though.
 
This is basically my problem: It is simply meant to display the 'help' section, however it just goes to the proceed part. I've tried swapping the if statements around and whatnot, but nothing seems to work. Swapping it around caused it to have a reverse effect, where if you typed in help the help menu would appear, however if you typed in proceed the help menu would show up regardless.
gMJ1uas.png
 
The code is below (including the if statements. this is the entire code from the main class, hopefully it's not too messy!)

 

import java.util.Scanner; //Enables a scanner for the class.


public class Main
{
public static void main (String[] args)
{
Scanner scanner = new Scanner(System.in);

System.out.println("Welcome to BTEC Calculator");
System.out.println("");

boolean gameRunning=true; //Tells the engine the game is running.

while (gameRunning) //Menu, User Choice
{
System.out.println("Enter 'proceed' if you want to begin the calculator.");
System.out.println("Enter 'help' if you need guidance on how the calculator works.");
String userOption = scanner.nextLine();

if (userOption.equals("proceed") || userOption.equals("Proceed") || userOption.equals("Go") || userOption.equals("Go") || userOption.equals("enter") || userOption.equals("Enter")); //This offers all the range of possible answers for proceeding to the game.
{
System.out.println("You are now ready to proceed. To begin, enter your name.");

String name = scanner.nextLine();
Student student1 = new Student(name);
System.out.println("");
System.out.println("Now enter your UCAS points for your BTEC grade.");

int ucaspoints = Integer.parseInt(scanner.nextLine());


System.out.println("Welcome " + name + ", based on your UCAS points, we will now convert your UCAS points into a BTEC grade.");
System.out.println("__________________________________________________________________________________________________________");
System.out.println("Student name is " + name + ", you also have " + ucaspoints + " UCAS points.");


if (ucaspoints < 120) //If the user enters their UCAS points lower than 120, then it will show the line of text below.
{
System.out.println("Your UCAS points are lower than the minimum grade. You have no grade.");
}
else if (ucaspoints < 160)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC PPP grade. (Pass Pass Pass)");
}
else if (ucaspoints < 200)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC MPP grade. (Merit Pass Pass)");
}
else if (ucaspoints < 240)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC MMP grade. (Merit Merit Pass)");
}
else if (ucaspoints < 280)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC MMM grade. (Merit Merit Merit)");
}
else if (ucaspoints < 320)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC DMM grade. (Distinction Merit Merit)");
}
else if (ucaspoints < 360)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC DDM grade. (Distinction Distinction Merit)");
}
else if (ucaspoints < 380)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC DDD grade. (Distinction Distinction Distinction)");
}
else if (ucaspoints < 400)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC D*DD grade. (Distinction* Distinction Distinction)");
}
else if (ucaspoints < 420)
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a BTEC D*D*D grade. (Distinction* Distinction* Distinction)");
}
else if (ucaspoints > 420) //For any value greater than 420 it will show the line of text below.
{
System.out.println("Your UCAS points of " + ucaspoints + " equal a maximum BTEC D*D*D* grade. Well done! (Distinction* Distinction* Distinction*)");
}
}

if (userOption.equals("help") || userOption.equals("Help")); //All possible user answers are listed here.
{
System.out.println("Welcome to the Help Menu.");
System.out.println("");
System.out.println("Please Note: This is a BTEC Extended Diploma Calculator.");
System.out.println("");
System.out.println("Once the calculator begins, enter your full name.");
System.out.println("");
System.out.println("Once you have entered your full name, enter the UCAS points you have received, where you'll then receive your BTEC grade in PPP format (example.)");
System.out.println("");
System.out.println("The BTEC grade you receive is required to be entered in CV's and anything relating to qualifications, therefore your BTEC grade is important to know.");
System.out.println("");

System.exit(1);

}

}

}
}

Student Life Build Yo: Windows 10 Pro 64-bit, Intel Core i5-3350p, ASRock H61M-VG4, Sapphire Nitro R9 380x

12GB DDR3-1333, Corsair CX600, SanDisk 120GB SSD, Asus Xonar DGX, Corsair 200R, Headphones: Takstar HI 2050.

~First PC Build!~

 

Link to post
Share on other sites

I don't see an if statement to test for a "help" response. It should come following getting input from the scanner. I see one way further down, which doesn't seem like the correct location.

Also, if statements shouldn't have semi-colons, as stated by fizzlesticks above.

 

Also, your system.exit(1) is inside where the "help" print statements are, which means, when you type in help your program exits. Is this wanted behavior? 

 

 

You should also try and look into case statements to improve readability.

 

By the way, Java has a string manipulation function .equalsIgnoreCase() which compares them, ignoring case sensitivity.

Similarly, you could also use a .toUpperCase() or .toLowerCase() simply for testing. Take the input typed in, manipulate it to all lowercase, then check if they typed in what was expected.

Link to post
Share on other sites

As fizzlesticks mentioned, you have a semicolon here:

 

if (userOption.equals("proceed") || userOption.equals("Proceed") || userOption.equals("Go") || userOption.equals("Go") || userOption.equals("enter") || userOption.equals("Enter")); //This offers all the range of possible answers for proceeding to the game.

 

Also, assuming this is some kind of homework or such, did you have to use the if else if method? There are better ways to do what you're trying to do.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×