Question

In: Computer Science

JAVA Project: Student Major and status Problem Description: Write a program that prompts the user to...

JAVA

Project: Student Major and status

Problem Description: Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is a number character 1, 2, 3 or 4, which indicates whether a student is a freshman, a sophomore, junior or senior. Suppose the following characters are used to denote the majors:

M: Mathematics

C: Computer Science

I: Information Technology

Here is a sample run: Sample: Enter two characters: M3 Mathematics Junior Enter two characters: C4 Computer Science Senior Enter two characters: T3 Invalid input: Wrong major code Enter two characters: I5 Information Technology Invalid input: wrong status code

What to deliver? Your .java file including: • All the above sample runs Your code with other appropriate comments.

Hint:

1. Use charAt() and if else loops

2. Use the sample run in the instruction to test your program to make sure it is correct before you submit it.

Solutions

Expert Solution

Please find the code below:::

StudentMajor.java

package classes3;

import java.util.Scanner;

public class StudentMajor {
   public static void main(String[] args) {
      
       Scanner sc = new Scanner(System.in);
       String input;
       while(true){
           System.out.print("\nEnter two characters : ");
           input = sc.nextLine();
           boolean valid = true;
           if(input.length()==2){
               if(input.charAt(0)=='M'){
                   System.out.print("Mathematics ");
               }else if(input.charAt(0)=='C'){
                   System.out.print("Computer Science ");
               }else if(input.charAt(0)=='I'){
                   System.out.print("Information Technology ");
               }else{
                   System.out.println("Invalid input: Wrong major code");
                   valid = false;
               }
               if(valid){
                   if(input.charAt(1)=='1'){
                       System.out.print("freshman ");
                   }else if(input.charAt(1)=='2'){
                       System.out.print("a sophomore");
                   }else if(input.charAt(1)=='3'){
                       System.out.print("junior ");
                   }else if(input.charAt(1)=='4'){
                       System.out.print("senior ");
                   }else{
                       System.out.println("Invalid input: wrong status code");
                       valid = false;
                   }
               }
           }else{
               System.out.println("Invalid input");
           }
       }
      
   }
}

output:


Related Solutions

Write a program in JAVA that prompts the user for a lower bound and an upper...
Write a program in JAVA that prompts the user for a lower bound and an upper bound. Use a loop to output all of the even integers within the range inputted by the user on a single line.
Write a JAVA program that prompts the user for the number of names they’d like to...
Write a JAVA program that prompts the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a JAVA program that prompts the user to enter a single name. Use a for...
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Problem description Write a C++ program that prompts the user to enter two non-negative integers, firstNum...
Problem description Write a C++ program that prompts the user to enter two non-negative integers, firstNum and secondNum. The program then prints all palindromic primes (Links to an external site.) between firstNum and secondNum, inclusive. A palindromic number is a number whose digits are the same forward or backward (e.g., 12321). A palindromic prime is a prime number that is also a palindromic number (e.g., 101). You must implement and use the following functions as prototyped below: /// --------------------------------------------------------------- ///...
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user...
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user to enter a capital for a state (by getting a state/capital pair via the StateCapitals class. Upon receiving the user’s input, the program reports whether the answer is correct. The program should randomly select 10 out of the 50 states. Modify your program so that it is guaranteed your program never asks the same state within one round of 10 guesses.
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
Use Java (Geometry: point in a rectangle?) Write a program that prompts the user to enter...
Use Java (Geometry: point in a rectangle?) Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5.  For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle. (Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to10 / 2 and its vertical...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT