Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PayCalculator
- {
- public static void main(String []args)
- {
- Scanner input = new Scanner(System.in);
- int PRIVATE = 20000;
- int SERGEANT = 34000;
- int LIEUTENANT = 42000;
- int COLONEL = 76000;
- int rank = 0;
- int base = 0;
- int SALARY = 0;
- int BONUS = 8000;
- // for loop begins when x=1
- // and runs till x <=4
- for (int x = 1; x <=4; x++)
- {
- System.out.print("Welcome to the pay calculator.\n");
- System.out.print("1=private, 2=sergeant, 3=lieutenant, 4=colonel\n");
- System.out.print("Please enter the number that signifies your rank: ");
- rank = input.nextInt();
- System.out.print("\n");
- switch (rank)
- {
- case 1:
- SALARY = SALARY + PRIVATE;
- break;
- case 2:
- SALARY = SALARY + SERGEANT;
- break;
- case 3:
- SALARY = SALARY + LIEUTENANT;
- break;
- case 4:
- SALARY = SALARY + COLONEL;
- break;
- default:
- System.out.print("Invalid choice, no pay added.\n");
- break;
- }
- System.out.print("Do you work on base?\n");
- System.out.print("Enter 1 for YES and 2 for NO: ");
- base = input.nextInt();
- System.out.print("\n");
- switch (rank)
- {
- case 1:
- SALARY = SALARY + BONUS;
- break;
- case 2:
- SALARY = SALARY;
- break;
- default:
- System.out.print("Invalid choice, no pay added.\n");
- break;
- }
- System.out.print("Your pay is " + SALARY + ".\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement