Intro to programming concepts: JAVA 1 Assume qualified is already declared. Code
ID: 3811141 • Letter: I
Question
Intro to programming concepts: JAVA 1Assume 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: “Sorry, you’re not eligible for a discount.” Intro to programming concepts: JAVA 1
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: “Sorry, you’re not eligible for a discount.”
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: “Sorry, you’re not eligible for a discount.” 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: “Sorry, you’re not eligible for a discount.”
Explanation / Answer
SwitchDemo.java
public class SwitchDemo {
public static void main(String[] args) {
//Declared and initialized integer type variable
int qualified=1;
//Based on the qualified value the corresponding case will get executed
switch(qualified)
{
case 1:
case 2:
System.out.println("You are a student or teacher and you get a 10% discount.");
break;
case 3:
case 4:
System.out.println("You are a senior citizen or military and you get a 12% discount.");
default:
System.out.println("Sorry, you’re not eligible for a discount.");
}
}
}
__________________
output:
You are a student or teacher and you get a 10% discount.
__________________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.