Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Jennifer Blom
- * Assignment #3
- * Calculate net pay after taking out medicare and Social security from the gross pay.
- */
- package ProgramAssignment3;
- import javax.swing.*;
- import java.util.*;
- public class Main {
- private static double SHIFT_RATE = 1.25;
- private static double WEEKEND_RATE = 1.50;
- private static double SS_TAX_PERCENT = .062;
- private static double MEDI_TAX_PERCENT = .0145;
- private static double socialSecurityWithholding;
- private static double netPay;
- public static void main(String[] args) {
- GetInputData();
- }
- public static void GetInputData() {
- // Create an instance of Scanner so I can get input from the keyboard
- Scanner keyboard = new Scanner(System.in);
- // input of variables first will display a prompt next gets input
- System.out.println("Employee Name: ");
- String employeeName = keyboard.nextLine();
- System.out.println("Enter Hourly Rate: ");
- double hourlyRate = keyboard.nextDouble();
- System.out.println("Enter Regular Hours: ");
- double regularHours = keyboard.nextDouble();
- System.out.println("Enter Overtime Hours: ");
- double overtimeHours = keyboard.nextDouble();
- System.out.println("Enter Shift Hours: ");
- double shiftHours = keyboard.nextDouble();
- System.out.println("Enter Weekend Hours: ");
- double weekendHours = keyboard.nextDouble();
- double regularPay = regularHours * hourlyRate;
- double overtimePay = overtimeHours * (hourlyRate * 1.5);
- double shiftPay = shiftHours * SHIFT_RATE;
- double weekendPay = weekendHours * WEEKEND_RATE;
- double grossPay = CalculateGrossPay(regularPay, overtimePay, shiftPay, weekendPay);
- double socialSecurityWithholding = CalculateSocSec(grossPay);
- double medicareWitholding = CalculateMedicare(grossPay);
- double netPay = CalculateNetPay(socialSecurityWithholding, medicareWitholding);
- PrintResults(employeeName, regularHours, overtimeHours, shiftHours, weekendHours, hourlyRate, regularPay, overtimePay, shiftPay, weekendPay, grossPay, medicareWithholding, socialSecurityWithholding, netPay);
- }
- public static double CalculateGrossPay(double regularPay, double overtimePay, double shiftPay, double weekendPay){
- double grossPay = regularPay + overtimePay + shiftPay + weekendPay;
- return grossPay;
- }
- public static double CalculateSocSec(double grossPay){
- socialSecurityWithholding = grossPay * SS_TAX_PERCENT;
- }
- public static double CalculateMedicare(double grossPay){
- double medicareWithholding = grossPay * MEDI_TAX_PERCENT;
- return medicareWithholding;
- }
- public static double CalculateNetPay(double grossPay, double medicareWithholding){
- netPay = grossPay - (socialSecurityWithholding + medicareWithholding);
- }
- public static void PrintResults() {
- //print the results to screen.
- System.out.println();
- System.out.println("Employee: " + employeeName);
- System.out.println("Regular hours worked: " + regularHours);
- System.out.println("Overtime Hours Worked: " + overtimeHours);
- System.out.println("Shift Hours Worked: " + shiftHours);
- System.out.println("Weekend Hours Worked: " + weekendHours);
- System.out.println("Hourly Rate: " + hourlyRate);
- System.out.println("Regular pay: " + regularPay);
- System.out.println("Overtime pay: " + overtimePay);
- System.out.println("Shift pay: " + shiftPay);
- System.out.println("Weekend pay: " + weekendPay);
- System.out.println("Gross pay: " + grossPay);
- System.out.println("Medicare Withholding: " + medicareWithholding);
- System.out.println("Social Security: " + socialSecurityWithholding);
- System.out.println();
- System.out.println("Net Pay: " + netPay);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement