Variables have been declared: int jobCode; double payRate; Rewrite the following if statement using a switch statement. Write the most efficient code with no code duplication. if(benefitLevel= = 999) { System.out.println("Error"); deduction = 0.0; } else if(benefitLevel= = 10 || benefitLevel= = 20) deduction= 17.95; else if(benefitLevel == 30) deduction= 22.50; else if(benefitLevel== 40) deduction= 36.50; else if(benefitLevel= = 50) deduction= 51.50; else { System.out.println("Error"); deduction= 0.0; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 15PE
icon
Related questions
Question
Variables have been declared:
int jobCode; double payRate;
Rewrite the following if statement using a switch statement. Write the most efficient code with no code duplication.
if(benefitLevel == 999)
{ System.out.println("Error");
deduction= 0.0; }
else if(benefitLevel == 10 || benefitLevel == 20)
deduction= 17.95;
else if(benefitLevel == 30) deduction= 22.50;
else if(benefitLevel==40) deduction= 36.50;
else if(benefitLevel== 50) deduction= 51.50;
else { System.out.println("Error");
deduction= 0.0; }
Transcribed Image Text:Variables have been declared: int jobCode; double payRate; Rewrite the following if statement using a switch statement. Write the most efficient code with no code duplication. if(benefitLevel == 999) { System.out.println("Error"); deduction= 0.0; } else if(benefitLevel == 10 || benefitLevel == 20) deduction= 17.95; else if(benefitLevel == 30) deduction= 22.50; else if(benefitLevel==40) deduction= 36.50; else if(benefitLevel== 50) deduction= 51.50; else { System.out.println("Error"); deduction= 0.0; }
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT