I should Define four boolean variables as follows:
the user enters the course code, then I decide which level is the student (user) and then define the 4 boolean variables depending on the level.
But I don't know how to do the equal()
for two thing or more.
this is my code:
import java.util.*;
public class point8 {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// declaring
String CourseCode, Level;
boolean Freshman, Sophomore, Junior, Senior;
// input
System.out.println("Course code:");
CourseCode = input.next().toUpperCase();
System.out.println("\nCourse Code: " + CourseCode);
// output
Level = CourseCode.substring(CourseCode.length() - 1);
System.out.println("Student Level: " + Level);
Freshman = Level.equals("1");
System.out.println("Freshman: " + Freshman);
Sophomore = Level.equals("3");
System.out.println("Sophomore: " + Sophomore);
Junior = Level.equals("6");
System.out.println("Junior: " + Junior);
Senior = Level.equals("9");
System.out.println("Senior: " + Senior);
}
}
What shall I do to compare from level 1 or 2 for freshman and compare from level 3 to 5 for Sophomore ?
if(Level.equals("9") || Level.equals("10"))
{
//Senior
}
Update: The OR operator is something you should learn in the first couple weeks. The only thing more basic is to just write out the second if statement.
if(Level.equals("9"))
{
//Senior
}
else if(Level.equals("10"))
{
//Senior
}