Answer:
- import java.util.Scanner;
- public class Main {
-
- public static void main(String[] args) {
-
- Scanner input = new Scanner(System.in);
- System.out.print("Please enter two characters: ");
- String inputStr = input.nextLine();
-
- if(inputStr.charAt(0) == 'B' || inputStr.charAt(0) == 'b'){
- System.out.println("Biology");
- }
- else if(inputStr.charAt(0) == 'C' || inputStr.charAt(0)== 'c'){
- System.out.println("Computer Science");
- }
- else if(inputStr.charAt(0) == 'I' || inputStr.charAt(0) == 'i')
- {
- 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.
They are versatile because they can be used for all sorts of tasks. They can also do many of the same tasks in different ways. They are diligent because they will do a task thoroughly until it is finished.
They work at a constant speed to do the task. Unlike a human, they will not slow down or get bored or start making mistakes that they were not doing earlier. So once they are programmed correctly to do a task, they will do it diligently.
To add while loop in python language, the use of syntax is to be brought into the effect.
<h3>What is a while loop?</h3>
A while loop can be referred to as an expression of code-blocks being true to their cores. Until the blocks of the code are not proved to be true, the loop continues.
In order to add such while loop to your code, one needs to use the syntax function in python to prove the true and correctness of the code blocks.
Hence, the procedure to add while loop has been aforementioned.
Learn more about a while loop here:
brainly.com/question/15690925
#SPJ1