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 to do the following: Specifics: Write an application that prompts a user...
Write a Java program to do the following: Specifics: Write an application that prompts a user for two integers and displays every integer between them. Display a message if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. Save the file as InBetween.java. Don’t forget to create the application/project  InBetweenTest.java Class that has the main method and an object to use the InBetween class.
Write a program that prompts the user for a grade (0-100), and asks if the student...
Write a program that prompts the user for a grade (0-100), and asks if the student is a graduate student or not. (Y/N).   If the student is a graduate student, the grade is reduced by 10%, because we have a higher expectation for graduate students, in an undergraduate class. The program then computes, and prints the letter grade based on the scale below. 90-100 A 80-89 B 70-79 C 60-69 D 0-60 F The program also provides feedback based on...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT