Java 1: Need help with E D. Assume qualified is already declared. Code a fall-th
ID: 3864598 • Letter: J
Question
Java 1: Need help with E
D. Assume qualified is already declared. Code a fall-through switch statement that will print the following messages:
When qualified is 1 and 2: “You are a student or teacher and you get a 10% discount.”
When qualified is 3 and 4: “You are a senior citizen or military and you get a 12% discount.”
When qualified is any other value:
int qualified=1;
switch(qualified)
{
case 1:
case 2:
System.out.printf("You are a student or teacher and you get a 10% discount.");
break;
case 3:
case 4:
System.out.printf("You are a senior citizen or military and you get a 12% discount.");
default:
System.out.printf("Sorry, you’re not eligible for a discount.");
E) Re-code 1d using double-selection ifs. You’ll use a conditional logical operator to join the sets of relational conditions (choose the right one):
Explanation / Answer
Answer:
int qualified=1;
if(qualified==1 || qualified == 2) {
System.out.printf("You are a student or teacher and you get a 10% discount.");
}
else if(qualified==3 || qualified == 4) {
System.out.printf("You are a senior citizen or military and you get a 12% discount.");
}
else{
System.out.printf("Sorry, you’re not eligible for a discount.");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.