Question

In: Computer Science

I needv pseudocode and a flowchart for the following java code public class AcmePay { public...

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);


}
}

Solutions

Expert Solution

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


Related Solutions

I need a java flowchart diagram for the following code: import java.util.*; public class Main {...
I need a java flowchart diagram for the following code: import java.util.*; public class Main {    public static void main(String[] args) {    Scanner sc=new Scanner(System.in);           System.out.print("Enter the input size: ");        int n=sc.nextInt();        int arr[]=new int[n];        System.out.print("Enter the sequence: ");        for(int i=0;i<n;i++)        arr[i]=sc.nextInt();        if(isConsecutiveFour(arr))        {        System.out.print("yes the array contain consecutive number:");        for(int i=0;i<n;i++)        System.out.print(arr[i]+" ");   ...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import...
Please I can get a flowchart and a pseudocode for this java code. Thank you //import the required classes import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BirthdayReminder {       public static void main(String[] args) throws IOException {        // declare the required variables String sName = null; String names[] = new String[10]; String birthDates[] = new String[10]; int count = 0; boolean flag = false; // to read values from the console BufferedReader dataIn = new BufferedReader(new...
How would I prepare pseudocode and a flowchart for this? import java.util.Scanner; public class HotDogsBuns {...
How would I prepare pseudocode and a flowchart for this? import java.util.Scanner; public class HotDogsBuns {    private static int HOTDOG_COUNT_PKG = 10;    private static int BUNS_COUNT_PKG = 8;       public static void main(String[] args) {        //Scanner object to get user input        Scanner keyboard = new Scanner(System.in);               // Get number of people        System.out.print("How many people will be competing in the contest?: ");        int noOfPeople = keyboard.nextInt();...
Please can I get a flowchart and pseudocode for this java code. Thank you. TestScore.java import...
Please can I get a flowchart and pseudocode for this java code. Thank you. TestScore.java import java.util.Scanner; ;//import Scanner to take input from user public class TestScore {    @SuppressWarnings("resource")    public static void main(String[] args) throws ScoreException {//main method may throw Score exception        int [] arr = new int [5]; //creating an integer array for student id        arr[0] = 20025; //assigning id for each student        arr[1] = 20026;        arr[2] = 20027;...
In Java I need a Flowchart and Code. Write the following method that tests whether the...
In Java I need a Flowchart and Code. Write the following method that tests whether the array has four consecutive numbers with the same value: public static boolean isConsecutiveFour(int[] values) Write a test program that prompts the user to enter a series of integers and displays it if the series contains four consecutive numbers with the same value. Your program should first prompt the user to enter the input size—i.e., the number of values in the series.
I need the Java Code and Flowchart for the following program: Suppose you are given a...
I need the Java Code and Flowchart for the following program: Suppose you are given a 6-by-6 matrix filled with 0s and 1s. All rows and all columns have an even number of 1s. Let the user flip one cell (i.e., flip from 1 to 0 or from 0 to 1) and write a program to find which cell was flipped. Your program should prompt the user to enter a 6-by-6 array with 0s and 1s and find the first...
Fix the following java code package running; public class Run {    public double distance; //in...
Fix the following java code package running; public class Run {    public double distance; //in kms    public int time; //in seconds    public Run prev;    public Run next;    //DO NOT MODIFY - Parameterized constructor    public Run(double d, int t) {        distance = Math.max(0, d);        time = Math.max(1, t);    }       //DO NOT MODIFY - Copy Constructor to create an instance copy    //NOTE: Only the data section should be...
In this Java lab, you use the flowchart and pseudocode found in the figure below to...
In this Java lab, you use the flowchart and pseudocode found in the figure below to add code to a partially created Java program. When completed, college admissions officers should be able to use the Java program to determine whether to accept or reject a student, based on his or her test score and class rank. Declare the variables testScoreString and classRankString. Write the interactive input statements to retrieve: A student’s test score (testScoreString) A student's class rank (classRankString) Write...
The following code is included for the java programming problem: public class Bunny {        private...
The following code is included for the java programming problem: public class Bunny {        private int bunnyNum;        public Bunny(int i) {               bunnyNum = i;        }        public void hop() {               System.out.println("Bunny " + bunnyNum + " hops");        } } Create an ArrayList <????> with Bunny as the generic type. Use an index for-loop to build (use .add(….) ) the Bunny ArrayList. From the output below, you need to have 5. Use an index for-loop...
In Java, please write a tester code. Here's my code: public class Bicycle {     public...
In Java, please write a tester code. Here's my code: public class Bicycle {     public int cadence; public int gear;   public int speed;     public Bicycle(int startCadence, int startSpeed, int startGear) {         gear = startGear;   cadence = startCadence; speed = startSpeed;     }     public void setCadence(int newValue) {         cadence = newValue;     }     public void setGear(int newValue) {         gear = newValue;     }     public void applyBrake(int decrement) {         speed -= decrement;    ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT