Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5.a Write a program that stores two integers and allows theuser to enter a chara

ID: 3609842 • Letter: 5

Question

5.a Write a program that stores two integers and allows theuser to enter a character.If the character is A, add the twointegers. If it is S, subtract the second integer from the first;if it is M, multiply the integers. Display the results of thearithmetic. Use a switch statement. If you don't know what a switch statement is, my teacher gavethis example from a power point: switch() { case 1: System.out.println(""); break; case 2: System.out.println(""); break; case 3: System.out.println(""); break; case 4: System.out.println(""); break; default: System.out.println(""); } I am really confused on how toincorporate this switch statement in the program. WILL GIVE BIG POINTS IF DONE CORRECTLY! HELP! 5.a Write a program that stores two integers and allows theuser to enter a character.If the character is A, add the twointegers. If it is S, subtract the second integer from the first;if it is M, multiply the integers. Display the results of thearithmetic. Use a switch statement. If you don't know what a switch statement is, my teacher gavethis example from a power point: switch() { case 1: System.out.println(""); break; case 2: System.out.println(""); break; case 3: System.out.println(""); break; case 4: System.out.println(""); break; default: System.out.println(""); } I am really confused on how toincorporate this switch statement in the program. WILL GIVE BIG POINTS IF DONE CORRECTLY! HELP! WILL GIVE BIG POINTS IF DONE CORRECTLY! HELP!

Explanation / Answer

please rate - thanks import java.util.*; public class calculator { public static void main(String []args) { int num1,num2,result=0; char choice='A'; Scanner keyboard = new Scanner(System.in); System.out.print("What is your first number "); num1 = keyboard.nextInt(); System.out.print("What is your second number "); num2 = keyboard.nextInt(); while(choice!='Q'&& choice!='q') { System.out.println( "choose an option" ); System.out.println( "A - Addition" ); System.out.println( "S - Subtraction" ); System.out.println( "M - Multiplication" ); System.out.println( "Q - Quit" ); choice=keyboard.next().charAt(0); switch (choice) {case 'A': case 'a': result=num1+num2;            System.out.println(num1+" + "+num2+" = "+result);            break; case 'S': case 's': result=num1-num2;             System.out.println(num1+" - "+num2+" = "+result);            break; case 'M': case 'm': result=num1*num2;             System.out.println(num1+" * "+num2+" = "+result); case 'q': case 'Q': break; default: System.out.println("Illegal input-retry"); } } }   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote