Write a program that prompts the user to enter two characters and display the corresponding major and year status. The first cha
racter indicates the major. And the second character is a number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. We consider only the following majors: B (or b): Biology
C (or c): Computer Science
I (or i): Information Technology and Systems
Note that your program needs to let the user know if the major or year is invalid. Also, your program should be case-insensitive: your program should tell "Biology" either user type ‘b’ or ‘B’.
Here are three sample runs:
Sample 1:
Enter two characters: i3
Information Technology and Systems
Junior
Sample 2:
Enter two characters: B5
Biology
Invalid year status
Sample 3:
Enter two characters: t2
Invalid major
Sophomore
What to deliver?
Your .java file including:
1. (Code: 5 points, Comments: 3 points) Your code with other appropriate comments.
2. (2 points) Four sample runs with the following four input:
(1) i3
(2) T2
(3) c2
(4) F0
Note that you need to run your program 4 times. Each time you run it, copy and paste the program output to the top of your program. After you finished these 4 runs, comment out the output you pasted so that you program would continue to run without any issue.
System.out.println("Information Technology and Systems");
}
else{
System.out.println("Invalid major");
}
int num = Character.getNumericValue(inputStr.charAt(1));
if(num >= 1 && num <= 4){
switch (num){
case 1:
System.out.println("freshman");
break;
case 2:
System.out.println("sophomore");
break;
case 3:
System.out.println("junior");
break;
case 4:
System.out.println("senior");
break;
}
}
else{
System.out.println("Invalid year status");
}
}
}
Explanation:
The code consists of two main parts. The part 1 is to validate the input major and print out the major according to the input character (Line 10 -22). If the input character is not matched with the target letters, a message invalid major will be displayed.
The part 2 is to validate the year status to make sure it only fall within the range of 1-4 (Line 26 -45). If within the range, the program will display the year major accordingly. If not a message invalid year status will be displayed.
A line of code to create a constant called MAX that will hold the size of an array that can store up to 25 decimal values. Separate each item with 1 space, and end the line with a semi-colon.