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

JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
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.
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
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: /// --------------------------------------------------------------- ///...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT