1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
stellarik [79]
3 years ago
15

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.
Computers and Technology
1 answer:
nydimaria [60]3 years ago
4 0

Answer:

  1. import java.util.Scanner;  
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        System.out.print("Please enter two characters: ");
  6.        String inputStr = input.nextLine();
  7.        if(inputStr.charAt(0) == 'B' || inputStr.charAt(0) == 'b'){
  8.            System.out.println("Biology");
  9.        }
  10.        else if(inputStr.charAt(0) == 'C' || inputStr.charAt(0)== 'c'){
  11.            System.out.println("Computer Science");
  12.        }
  13.        else if(inputStr.charAt(0) == 'I' || inputStr.charAt(0) == 'i')
  14.        {
  15.            System.out.println("Information Technology and Systems");
  16.        }
  17.        else{
  18.            System.out.println("Invalid major");
  19.        }
  20.        int num = Character.getNumericValue(inputStr.charAt(1));
  21.        if(num >= 1 && num <= 4){
  22.            switch (num){
  23.                case 1:
  24.                    System.out.println("freshman");
  25.                    break;
  26.                case 2:
  27.                    System.out.println("sophomore");
  28.                    break;
  29.                case 3:
  30.                    System.out.println("junior");
  31.                    break;
  32.                case 4:
  33.                    System.out.println("senior");
  34.                    break;
  35.            }
  36.        }
  37.        else{
  38.            System.out.println("Invalid year status");
  39.        }
  40.    }
  41. }

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.

You might be interested in
Which audio format is used to create chiptunes?
Scilla [17]
Chiptune, also known as chip music or 8-bit music, is synthesized electronic music which is made for programmable sound generator suns chops used in vintage computers,consoles , and arcade machines.
5 0
3 years ago
Read 2 more answers
Select the correct answer.
zmey [24]

the answer should be the letter a

3 0
3 years ago
Read 2 more answers
What is a functional simulation?
Anika [276]
D) a type of training that allows...
4 0
3 years ago
Developed by Frank Vahid. Write a program using integers usernum and x as input, and output usernum divided by x four times. For
OleMash [197]

Answer:

Explanation:

Let's do this in Python. We will loop through 4 times, each of the loop would compute the dividend, store it as string in a result variable and finally print the result on the same line:

def divide_4_times(user_num, x):

    result = ''

    for i in range(4):

         user_num /= x

         result += (' ' + str(user_num))

   print(result)

7 0
3 years ago
Why is it preferable to code web pages in html format?
Ronch [10]
Depends on what you are working on.

If you are working on a website I recommend Adobe Dreamweaver CC.

if its small assignments that doesnt involve major work, I'd use something like notepad++
8 0
3 years ago
Read 2 more answers
Other questions:
  • Kevin wants an application that will help him create a website as well as publish it. What application can he use?
    9·1 answer
  • What type of Windows Server is the most likely server to be targeted by a computer hacker?
    13·2 answers
  • You just read an msds for acetic acid. based on what you read, what type of information is included in an msds sheet? record you
    7·1 answer
  • 2. What type of expansion card allows your computer to
    12·1 answer
  • A network address is 131.247.160.0/19. The 19 implies that
    5·1 answer
  • In addition to format commands that are found in the ribbon, which option is available for more extensive formatting?
    11·1 answer
  • What is the code i need to do
    12·1 answer
  • Who here has a crush on jk from bts but feels more mature than him
    10·2 answers
  • Which types of networks cover large geographical areas such as several states? PAN
    9·1 answer
  • ¿Cuál es la capacidad pulmonar del hombre y la mujer?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!