Question

Must be written in java. Modularize the following code. //CIS 183 Lab 4 //Joseph Yousef import...

Must be written in java. Modularize the following code.

//CIS 183 Lab 4
//Joseph Yousef
import java.util.*;
public class SalaryCalc
{
public static void main(String [] args)
{ Scanner input = new Scanner(System.in);
int sentinelValue = 1;
//initializes sentinelValue value to 1 to be used in while loop
while (sentinelValue == 1)
{
System.out.println("Enter 1 to enter employee, or enter 2 to end process: ");   
sentinelValue = input.nextInt();
input.nextLine();
System.out.println("enter employee name: ");
String employeeName = input.nextLine();
System.out.println("enter day shift or night shift (make sure to use all lowercase letters and no spaces please): ");
String employeeShift = input.nextLine();
System.out.println ("enter hours worked");
int hoursWorked;
hoursWorked = input.nextInt();
System.out.println ("enter hourly rate");
double hourlyRate;
hourlyRate = input.nextDouble();
//section of loop that gathers all data for the employee to be used in calculations
{
if (hoursWorked>40)
{
double overtimeHours;
overtimeHours = hoursWorked-40;
double overtimeRate;
overtimeRate = hourlyRate*1.5;
double overtimePay;
overtimePay = overtimeHours*overtimeRate;
double regularPay;
regularPay = hourlyRate*40;
double grossPay;
grossPay = overtimePay+regularPay;
//calculates all numbers for employee that has overtime hours
System.out.println("Employee's name is: " + employeeName);
if (employeeShift.equals("day"))
System.out.println("Friday pay period");
else if (hoursWorked < 40)
{
System.out.println("Saturday pay period");
System.out.println("Regular pay amount is $" + regularPay);
System.out.println("Overtime pay amount is $" + overtimePay);
System.out.println ("the gross pay is $" + grossPay);
//output process
}
}
else
{
double grossPay;
double overtimePay;
double regularPay;
grossPay = hoursWorked*hourlyRate;
regularPay = hoursWorked * hourlyRate;
overtimePay = 0;
//calculates numbers for employee without overtime
System.out.println("Employee's name is: " + employeeName);
if (employeeShift.equals("day"))
System.out.println("Friday pay period");
else
System.out.println("Saturday pay period");
System.out.println("Regular pay amount is $" + regularPay);
System.out.println("Overtime pay amount is $" + overtimePay);
System.out.println ("the gross pay is $" + grossPay);
//output process
}
}
}
} //end main
} //end class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Modularize code

import java.util.*;
public class SalaryCalc
{
static Scanner input = new Scanner(System.in);
public static void main(String [] args)
{
int sentinelValue = 1;
//initializes sentinelValue value to 1 to be used in while loop
while (true)
{
System.out.println("Enter 1 to enter employee, or enter 2 to end process: ");   
sentinelValue = input.nextInt();
if(sentinelValue==1)
{
takeUserInput();
}
else
break;
}
}//end main

public static void takeUserInput()
{
  
int hoursWorked;
double hourlyRate;
input.nextLine();
System.out.println("enter employee name: ");
String employeeName = input.nextLine();
System.out.println("enter day shift or night shift (make sure to use all lowercase letters and no spaces please): ");
String employeeShift = input.nextLine();
System.out.println ("enter hours worked");
hoursWorked = input.nextInt();
System.out.println ("enter hourly rate");
hourlyRate = input.nextDouble();
calculatePay(employeeName,employeeShift,hoursWorked,hourlyRate);
}

private static void calculatePay(String employeeName, String employeeShift, int hoursWorked, double hourlyRate)
{
double overtimeHours;
double overtimeRate;
double overtimePay;
double regularPay;
double grossPay;
if (hoursWorked>40)
{   
overtimeHours = hoursWorked-40;
overtimeRate = hourlyRate*1.5;
overtimePay = overtimeHours*overtimeRate;
regularPay = hourlyRate*40;
grossPay = overtimePay+regularPay;
}
else
{
grossPay = hoursWorked*hourlyRate;
regularPay = hoursWorked * hourlyRate;
overtimePay = 0;
}
printSalary(employeeName,employeeShift,regularPay,overtimePay,grossPay);
}

private static void printSalary(String employeeName, String employeeShift, double regularPay, double overtimePay, double grossPay)
{
System.out.println("Employee's name is: " + employeeName);
if (employeeShift.equals("day"))
System.out.println("Friday pay period");
else
System.out.println("Saturday pay period");
System.out.println("Regular pay amount is $" + regularPay);
System.out.println("Overtime pay amount is $" + overtimePay);
System.out.println ("the gross pay is $" + grossPay);
}
}//end class
  
output

  

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Must be written in java. Modularize the following code. //CIS 183 Lab 4 //Joseph Yousef import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following Java code outputs various amounts for a worker based on skill level, hours worked,...

    The following Java code outputs various amounts for a worker based on skill level, hours worked, and insurance: import java.util.Scanner; public class Pay { public static void main(String[] args) { int SkillOneRate = 17; int SkillTwoRate = 20; int SkillThreeRate = 22; double MedicalInsurance = 32.50; double DentalInsurance = 20.00; double DisabilityInsurance = 10.00; int skill,hours; int choice; char y; char n; int payRate =0; double regularPay = 0; double overtimePay = 0; double grossPay=0; double deductions=0; double netPay =...

  • I need this java program to contain methods that do some of the work that can...

    I need this java program to contain methods that do some of the work that can be modularized. It must logically be the same as this loop program but instead the logic will be modularized into Java Methods. Continue to take input for every employee in a company, and display their information until a sentinel value is entered, that exits the loop and ends the program. import java.util.Scanner; public class SalaryCalc { double Rpay = 0, Opay = 0; void...

  • This is my code but my overtime calculation is wrong and I cant figure out how...

    This is my code but my overtime calculation is wrong and I cant figure out how to round to two decimal places import java.util.Scanner; public class HourlyWage { public static void main(String[] args) { //Variables double totalWage; double totalOvertimePay; double totalPay; String name; double overtimeHours = 0.0; double hoursWorked = 0.0; double hourlyWage = 0.0; Scanner keyboard = new Scanner(System.in); System.out.println("Please enter your name "); name = keyboard.next(); System.out.println("Please enter your hourly wage "); hourlyWage = keyboard.nextDouble(); System.out.println("How many hours...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • Chapter 4 Loop logic and using loop logic for File Input/0utput. 1. Read Chapter 4 sections...

    Chapter 4 Loop logic and using loop logic for File Input/0utput. 1. Read Chapter 4 sections 4.10 until end of chapter. 2. Review Questions and Exercises, short answers. 3. [20 points] submit SalaryCalcLoopFile.java Let's update our program, SalaryCalcLoop.java, from last week, to now take input about each employee from a file and write their information and salary/pay information to a file. use input file, where each employee has name,shift,hours worked,hourly rate: EmployeePayroll.txt output file should be named: EmployeePayStubs.txt EmployeePayroll.txt Rashid...

  • THIS CODE SHOULD BE MODIFIED TO READ SuperMarket.dat instead of Inputting and Outputting. SuperMarket.dat Monday 4...

    THIS CODE SHOULD BE MODIFIED TO READ SuperMarket.dat instead of Inputting and Outputting. SuperMarket.dat Monday 4 Monday 6 Monday 2 Tuesday 3 Tuesday 2 Wednesday 3 Wednesday 5 Wednesday 7 Thursday 5 Friday 4 Friday 3 Friday 4 Saturday 8 Saturday 8 Saturday 8 Sunday 0 QUESTION: Write the control break code, including the code for the dayChange() method, in the main() method. // SuperMarket.java - This program creates a report that lists weekly hours worked // by employees of...

  • Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    //...

    Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    // checks customers in and assigns them a boarding pass    // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers    //    public void reserveSeats()    {       int counter = 0;       int section = 0;       int choice = 0;       String eatRest = ""; //to hold junk in input buffer       String inName = "";      ...

  • Identify a logical error in the following code and fix it. public class test1 {    ...

    Identify a logical error in the following code and fix it. public class test1 {     public static void main(String[] args){         int total;         float avg;         int a, b, c;         a=10;         b=5;         c=2;         total=a+b+c;         avg=total/3;         System.out.println("Average: "+avg);     } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

  • Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...

    Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT