Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * 2PayStub class is part of Lab 3 and
- * creates a simple pay stub.
- *
- * @author Elizabeth Gibson
- * @version September 19, 2017
- */
- public class PayStub
- {
- public static final double OVERTIME_FACTOR = 1.5;
- public static final double SOCIAL_WITHHOLDING = .10;
- public static final double FEDERAL_TAX = .20;
- private String employeeName;
- private String ssN;
- private int hours;
- private int overTime;
- private double payRate;
- private double regularPay;
- private double overTimePay;
- private double overTimeRate;
- private double grossPay;
- private double ssW;
- private double fedTax;
- private double netPay;
- private double margeHourlyRate;
- private double margeGrossPay;
- /**
- * It all starts with the main method.
- *
- * @param args Command-line arguments.
- */
- public static void main(String[] args)
- {
- Scanner reader = new Scanner(System.in);
- PayStub homer = new PayStub(reader);
- PayStub marge = new PayStub(reader);
- PayStub lisa = new PayStub(reader);
- }
- /**
- * Constructor.
- *
- * @param keyboard Scanner object.
- */
- public PayStub(Scanner keyboard)
- {
- getInput(keyboard);
- keyboard.nextLine();
- calculate();
- printPayStub();
- }
- /**
- * Accessor for overTime.
- */
- public int getoverTime()
- {
- return overTime;
- }
- /**
- * Accessor for grossPay.
- */
- public double getgrossPay()
- {
- return grossPay;
- }
- /**
- * Accessor for margeHourlyRate.
- */
- public double margeHourlyRate()
- {
- margeHourlyRate = 20.0;
- return margeHourlyRate;
- }
- public void setmargeHourlyRate(double hours)
- {
- margeHourlyRate = hours;
- }
- public double getmargeGrossPay()
- {
- grossPay = payRate * margeHourlyRate;
- return margeGrossPay;
- }
- /**
- * Mutator for overTime.
- *
- * @param newValue Set the object's value to the supplied value.
- */
- public void setoverTime(int newValue)
- {
- if (newValue >= 0)
- {
- overTime = newValue;
- calculate();
- }
- }
- /**
- * Mutator for payRate.
- *
- * @param newValue1 Set the object's value to the supplied value.
- */
- public void setpayRate(double newValue)
- {
- if (newValue >= 0)
- {
- payRate = newValue;
- calculate();
- }
- }
- /**
- * Get input from the user.
- *
- * @param keyboard Scanner object.
- */
- private void getInput(Scanner keyboard)
- {
- //get employee's name
- System.out.print("Enter employee name: ");
- employeeName = keyboard.nextLine();
- //employee social security number
- System.out.print("Enter employee SSN: ");
- ssN = keyboard.nextLine();
- //employee's regular not overtime hours worked
- System.out.print("Enter number of regular hours: ");
- hours = keyboard.nextInt();
- //overtime hours worked
- System.out.print("Enter number of overtime hours: ");
- overTime = keyboard.nextInt();
- //hourly payRate
- System.out.print("Enter hourly pay rate: ");
- payRate = keyboard.nextDouble();
- System.out.printf("New gross pay: $%-8.2f\n", getmargeGrossPay());
- }
- /**
- * This function separates the calculations from the interface.
- */
- private void calculate()
- {
- regularPay = hours * payRate;
- overTimeRate = payRate * OVERTIME_FACTOR;
- overTimePay = overTime * overTimeRate;
- grossPay = regularPay + overTimePay;
- ssW = SOCIAL_WITHHOLDING * grossPay;
- fedTax = FEDERAL_TAX * (grossPay - ssW);
- netPay = grossPay - (ssW + fedTax);
- }
- /**
- * Print out the calculated pay stub.
- * This method should only be called after the calculate method.
- */
- private void printPayStub()
- {
- System.out.println("____________________________________"
- + "_________________________________________");
- String format = "Name: %-37s SSN: %-11s\n";
- System.out.printf(format, employeeName, ssN);
- String format1 = "Regular Hours: %-8d Reg Rate: $%-8.2f"
- + " Reg Pay: $%-8.2f\n";
- System.out.printf(format1, hours, payRate, regularPay);
- String format2 = "Overtime Hours: %-8d"
- + "OT Rate: $%-9.2f OT Pay: $%-8.2f\n";
- System.out.printf(format2, overTime, overTimeRate, overTimePay);
- String format3 = "Gross Pay: $%-8.2f\n";
- System.out.printf(format3, grossPay);
- String format4 = "SS Withholding: $%-8.2f\n";
- System.out.printf(format4, ssW);
- String format5 = "Federal Tax: $%-8.2f\n";
- System.out.printf(format5, fedTax);
- String format6 = "Net Pay: $%-8.2f\n";
- System.out.printf(format6, netPay);
- System.out.print("____________________________________"
- + "_________________________________________\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement