import java.util.Scanner; public class Main {     public static final double OVERTIME_RATE = 1.5;     public static final double HOLD = .1;     public static final double TAX = .2;     public static void main(String[] args)     {         Scanner sc = new Scanner(System.in);         System.out.print("Name: ");         String name = sc.nextLine();         System.out.print("SSN: ");         String ssn

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

import java.util.Scanner;
public class Main
{
    public static final double OVERTIME_RATE = 1.5;
    public static final double HOLD = .1;
    public static final double TAX = .2;
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Name: ");
        String name = sc.nextLine();
        System.out.print("SSN: ");
        String ssn = sc.nextLine();
        int regularHours;
        System.out.print("Regular Hours: ");
        regularHours = sc.nextInt();
        int overtimeHours;
        System.out.print("Overtime Hours: ");
        overtimeHours = sc.nextInt();
        double hourlypayRate;
        System.out.print("Hourly pay rate: $");
        hourlypayRate = sc.nextDouble();
        double regularPay = regularHours * hourlypayRate;
        double overtimeRate = hourlypayRate * OVERTIME_RATE;
        double overtimePay = overtimeHours * OVERTIME_RATE * hourlypayRate;
        double gross = regularPay + overtimePay;
        double wh = gross * HOLD;
        double fTax = (gross - wh) * TAX;
        double net = gross - wh - fTax;
        System.out.println("___________________________________________________"+ "_________________");
        String format = "Name: %-37s SSN: %-11s\n";
        System.out.printf(format, name, ssn);
        format = "Regular Hours: %-8d Reg Rate: $%-8.2f Reg Pay: $%-8.2f\n";
        System.out.printf(format, regularHours, hourlypayRate, regularPay);
        format = "Overtime Hours: %-8dOT Rate: $%-8.2f OT Pay: $%-8.2f\n";
        System.out.printf(format, overtimeHours, overtimeRate, overtimePay);
        format = "Gross Pay: $%-8.2f\n";
        System.out.printf(format, gross);
        format = "SS Withholding: $%-8.2f\n";
        System.out.printf(format, wh);
        format = "Federal Tax: $%-8.2f\n";
        System.out.printf(format, fTax);
        format = "Net Pay: $%-8.2f\n";
        System.out.printf(format, net);
        System.out.println("___________________________________________________"+ "_________________");

    }
}

Using the above code create a class. The class Activity2PayStub will have four methods in it. Create the three new methods below the main method  i.e., after the brace that closes main  like so:
public static void main(String[] args)
{
... code from the above code is in here now ...
... Don't modify the main yet...
}
public void getInput(Scanner keyboard)
{
}
public void calculate()
{
}
public void printPayStub()
{

 

Expert Solution
Step 1

// Activity2PayStub.java

import java.util.Scanner;

public class Activity2PayStub{
  
   // constants
   public static final double OVERTIME_RATE = 1.5;
   public static final double SS_WITHHOLDING = .1;
   public static final double FEDERAL_TAX = .2;
  
   // fields
   private String name, ssn;
   private int regHours, overHours;
   private double hourlyRate, regPay, overRate, overPay, grossPay, ssWith, fedTax, netPay;

   public static void main(String[] args) {

       Scanner keyboard = new Scanner(System.in);
       // create an object of Activity2PayStub class
       Activity2PayStub a2ps = new Activity2PayStub();
       // get inputs
       a2ps.getInput(keyboard);
       // compute payments
       a2ps.calculate();
       // display information
       a2ps.printPayStub();
   }

   /**
   * method that takes inputs of name, ssn, regular hours, overtime hours
   * and hourly rate and set the fields to the values input by the user
   */
   public void getInput(Scanner keyboard)
   {
       System.out.print("Enter your name: ");
       name = keyboard.nextLine();
       System.out.print("Enter your SSN: ");
       ssn = keyboard.nextLine();
       System.out.print("Enter your regular hours: ");
       regHours = keyboard.nextInt();
       System.out.print("Enter your overtime hours: ");
       overHours = keyboard.nextInt();
       System.out.print("Hourly pay rate: $");
       hourlyRate = keyboard.nextDouble();
   }
  
   /**
   * method to calculate the regular pay, overtime rate and pay, gross pay
   * ssWitholding, federal tax and net pay
   */
   public void calculate()
   {
       regPay = regHours * hourlyRate;
       overRate = hourlyRate * OVERTIME_RATE;
       overPay = overHours * OVERTIME_RATE * hourlyRate;
       grossPay = regPay + overPay;
       ssWith = grossPay * SS_WITHHOLDING;
       fedTax = (grossPay - ssWith) * FEDERAL_TAX;
       netPay = grossPay - ssWith - fedTax;
   }
  
   /**
   * method to display the details input and calculated
   */
   public void printPayStub()
   {
       System.out.println("___________________________________________________"
               + "_________________");   
       String format = "Name: %-37s SSN: %-11s\n";
       System.out.printf(format, name, ssn);   
       format = "Regular Hours: %-8d Reg Rate: $%-8.2f Reg Pay: $%-8.2f\n";
       System.out.printf(format, regHours, hourlyRate, regPay);
       format = "Overtime Hours: %-7d OT Rate: $%-8.2f OT Pay: $%-8.2f\n";
       System.out.printf(format, overHours, overRate, overPay);
       format = "Gross Pay: $%-8.2f\n";
       System.out.printf(format, grossPay);
       format = "SS Withholding: $%-8.2f\n";
       System.out.printf(format, ssWith);
       format = "Federal Tax: $%-8.2f\n";
       System.out.printf(format, fedTax);
       format = "Net Pay: $%-8.2f\n";
       System.out.printf(format, netPay);   
       System.out.println("___________________________________________________"
               + "_________________");
   }
}

// end of Activity2PayStub.java

 

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education