In: Computer Science
I needv pseudocode and a flowchart for the following java code
public class AcmePay {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
int hours, shift, retirement = 0;
do {
System.out.print("Enter the number of hours worked (>0):
");
hours = scanner.nextInt();
} while (hours <= 0);
do {
System.out.print("Enter shift [1 2 or 3]: ");
shift = scanner.nextInt();
} while (shift < 1 || shift > 3);
if (shift == 2 || shift == 3) {
do {
System.out.print("Elect for retirement plan (1 for yes, 2 for
no): ");
retirement = scanner.nextInt();
} while (retirement < 1 || retirement > 2);
}
compute(hours, shift, retirement);
}
private static void compute(int hours, int shift, int retirement) {
System.out.println("Hours Worked: " + hours);
double regularPay = 0, overtimePay = 0, total = 0, deduction = 0,
netPay = 0;
if (shift == 1) {
System.out.println("Shift: First Shift");
if (hours <= 40) {
regularPay = hours * 17;
overtimePay = 0;
} else {
regularPay = 40 * 17;
overtimePay = (hours - 40) * 17 * 1.5;
}
total = regularPay + overtimePay;
} else if (shift == 2) {
System.out.println("Shift: Second Shift");
if (hours <= 40) {
regularPay = hours * 18.5;
overtimePay = 0;
} else {
regularPay = 40 * 18.5;
overtimePay = (hours - 40) * 18.5 * 1.5;
}
total = regularPay + overtimePay;
if (retirement == 1) {
deduction = 0.03 * total;
netPay = total - deduction;
}
} else if (shift == 3) {
System.out.println("Shift: Third Shift");
if (hours <= 40) {
regularPay = hours * 22;
overtimePay = 0;
} else {
regularPay = 40 * 22;
overtimePay = (hours - 40) * 22 * 1.5;
}
total = regularPay + overtimePay;
if (retirement == 1) {
deduction = 0.03 * total;
netPay = total - deduction;
}
}
System.out.printf("Regular Pay : $%10.2f\n", regularPay);
System.out.printf("Overtime Pay : $%10.2f\n", overtimePay);
System.out.printf("Total Pay : $%10.2f\n", total);
System.out.printf("Deduction : $%10.2f\n", deduction);
System.out.printf("Net Pay : $%10.2f\n", netPay);
}
}
PseudoCode as Follows :
1. Ask user to enter number of hours he worked .
2. If the value he entered is less than 0 , as that makes no
sense . Go Back to 1 (until he enters valid hours)
If the value enter is valid , Store it in Hours variable
3. Ask user to enter shift number .
4. If the value he entered is less than 1 or greater than 3 , as that makes no sense . Go Back to 3 (until he enters valid shift routine). If the value enter is valid , Store it in Shift variable
5. If Shift entered is 2 or 3 , Ask for his retirement plan (1 for yes, 2 for no).
6. If the value entered is other than 1 or 2 , as that makes no sense . Go Back to 5 (until he enters valid retirement plan). If the value entered is valid , Store it in Retirement variable
7. Goto 8 function compute(hours, shift, retirement); along with passing these 3 parameters
8. Print total hours worked
9. If shift == 1
print("first shift")
if(hours < 40)
regularPay = hours * 17
OvertimePay = 0
else
regularPay = 40 * 17
overtimePay = (hours - 40) * 17 * 1.5
total = regularPay + OvertimePay
10. If shift == 2
print("Second shift")
if(hours < 40)
regularPay = hours * 18.5
OvertimePay = 0
else
regularPay = 40 * 18.5
overtimePay = (hours - 40) * 18.5 * 1.5
total = regularPay + OvertimePay
if retirement == 1
deduction = 0.03 * total
netPay = total - deduction
11. If shift == 3
print("Third shift")
if(hours < 40)
regularPay = hours * 22
OvertimePay = 0
else
regularPay = 40 * 22
overtimePay = (hours - 40) * 22 * 1.5
total = regularPay + OvertimePay
if retirement == 1
deduction = 0.03 * total
netPay = total - deduction
14. Print everythin now (Regular Pay, OverTime Pay, Total Pay, Deduction, Net Pay)
Flowchart :
Since it was a huge code of around 60-70 lines , creating
flowchart was bit difficult
I am uploading two pics , In one page flowchart for Void Main
function was done
In 2nd page , flowchart for Compute function was made
I was unable to include 3 rd if case of shift==3 bcoz my page got
filled , but i have mentioned in note on the page
Really Sorry, for not completing the third shift parts due to page congestion . If you still need it . Do comment , I`ll make preparations