/* 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 number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. suppose the following chracters are used to denote the majors: m: mathematics c: computer science i: information technology*/import java.util.scanner; public class exercise_04_18{ public static void main(string[] args) { scanner in = new scanner(system.in); system.out.print("enter two characters: "); string status = in.next(); char major = character.touppercase(status.charat(0)); char year = status.charat(1); string coursename = ""; string yearname = ""; if (major == 'm' || major == 'i' || major == 'c') { switch(major) { case 'm': coursename = "mathematics"; break; case 'c': coursename = "computer science"; break; case 'i': coursename = "information technology"; break; default: break; } switch(year) { case '1': yearname = "freshman"; break; case '2': yearname = "sophmore"; break; case '3': yearname = "junior"; break; case '4': yearname = "senior"; break; default: break; } system.out.printf("%s %s%n", coursename, yearname); } else{ system.out.printf("invalid input.%n"); } }}

Solved
Show answers

Ask an AI advisor a question