U.S. federal govt. employees are paid on a scale according to their grade and st
ID: 3668652 • Letter: U
Question
U.S. federal govt. employees are paid on a scale according to their grade and step. There are a total of 15 grades, each of which consists of 10 steps. Here's a table of 2014 annual salaries (in $) for the first 3 grades and the first 5 steps from each grade:
Grade Step 1 Step 2 Step 3 Step 4 Step 5
1 17981 18582 19180 19775 20373
2 20217 20698 21367 21934 22179
3 22058 22793 23528 24263 24998
Write a Java program that uses the switch statement to determine the salary of an employee. Your program should allow the user toeneter two inputs: the rade and step. It should then display the appropriate salary based on the table above. You only have to implement the first 3 grades and the first 5 steps. Include default cases to cover situations where the user enters an invalid grade or step. DO NOT USE ANY FORM OF THE IF STATEMENT IN YOUR PROGRAM.
HINT: YOU CAN NEST SWITCH STATEMENTS, JUST AS YOU CAN NEST IF STATEMENTS!
Explanation / Answer
import java.util.Scanner;
public class GradeStep{
public static void main(String args[]){
int[] grade1 = {17981,18582,19180,19775,20373};
int[] grade2 = {20217,20698,21367,21934,22179};
int[] grade3 = {22058,22793,23528,24263,24998};
Scanner in = new Scanner(System.in);
System.out.print("Please enter grade(1 to 3): ");
int grade = in.nextInt();
System.out.print("Please enter Step (1 to 5): ");
int step = in.nextInt();
switch(grade)
{
case 1 :
switch(step)
{
case 1:
System.out.println("Salary is: "+grade1[0]);
break;
case 2:
System.out.println("Salary is: "+grade1[1]);
break;
case 3:
System.out.println("Salary is: "+grade1[2]);
break;
case 4:
System.out.println("Salary is: "+grade1[3]);
break;
case 5:
System.out.println("Salary is: "+grade1[4]);
break;
default:
System.out.println("Invalid Step!");
break;
}
break;
case 2 :
switch(step)
{
case 1:
System.out.println("Salary is: "+grade2[0]);
break;
case 2:
System.out.println("Salary is: "+grade2[1]);
break;
case 3:
System.out.println("Salary is: "+grade2[2]);
break;
case 4:
System.out.println("Salary is: "+grade2[3]);
break;
case 5:
System.out.println("Salary is: "+grade2[4]);
break;
default:
System.out.println("Invalid Step!");
break;
}
break;
case 3 :
switch(step)
{
case 1:
System.out.println("Salary is: "+grade3[0]);
break;
case 2:
System.out.println("Salary is: "+grade3[1]);
break;
case 3:
System.out.println("Salary is: "+grade3[2]);
break;
case 4:
System.out.println("Salary is: "+grade3[3]);
break;
case 5:
System.out.println("Salary is: "+grade3[4]);
break;
default:
System.out.println("Invalid Step!");
break;
}
break;
default :
System.out.println("Invalid grade");
}
}
}
//Hope it helps. :-)
//If you have any query or confusion, please leave a comment, I’ll try to explain in more details.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.