Question

In: Computer Science

Write the program in Java. Demonstrate that you know how to define variables, create conditional statements,...

Write the program in Java.

  1. Demonstrate that you know how to define variables, create conditional statements, write a loop, use arrays, obtain input from the user, display output, test and create a JavaDoc.

Create project PaystubTest2 that is a Paystub calculator with program Paystub##.java (where ## is your initials) based on user input. (10 points)

You must use the ReadStringFromUser and ReadFloatFromUser methods in the program to obtain user input. (20 points)

This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user. (50 points)

INPUT

The application must be able to collect the following “required” information for each employee:

  1. Name
  2. Hourly Wage (must be a positive number)
  3. Hours Worked (must be a positive number)
  4. Withholding Exemptions (valid values are from 0 to 10)
  5. Marital Status (Single or Married)

OUTPUT

These are the outputs:

  1. For each employee display the following:
    1. Gross Earnings
    2. FICA Tax (display both Medicare and Social Security taxes)
    3. Federal Income Tax Withheld
    4. Net Earnings

PROCESS

For each employee (HINT: Do while QUIT is not entered - if( strResponse.toUpperCase().equals("QUIT") )) calculate the following for their individual payroll for the week. Use an array to hold the gross pay amounts and print the grand payroll total once the user types QUIT.

Gross earnings: Hourly wage times hours worked (with time and a half after 40 hours).

FICA Tax: sum of 6.2% of the total wages (Social Security tax) and 1.45% of total wages (Medicare tax)

Federal Income Tax Withheld: Subtract $55.77 from the gross earnings for each withholding exemption giving the Adjusted Gross Income. Based on the Adjusted Gross Income, use the following parameters to determine the federal tax based on marital status:

Adjusted Gross Income

Income Tax Withheld (S)

Income Tax Withheld (M)

$0 to $50.99

$0

$0

$51 to $500.99

10% over $51

5% over $51

$501 to $2,500.99

$45.00 + 15% of amount over $500.00

$22.50 + 10% of amount over $500.00

$2,501 to $5,000

$345.00 + 20% of amount over $2,500

$225.50 + 15% of amount over $2,500

Over $5,000

$845.00 + 25% of amount over $5,000

$600.50 + 20% of amount over $5,000

Net Earnings: Gross Earnings – FICA taxes – Federal Income Tax Withheld

You must create a JavaDoc for this project. (10 points)

Be sure to include a print screen of your test results. (10 points)

Here is an example of the output format:

Paystub Calculator

-------------------------------------------------------

Employee Name:(type 'Quit' to end program)

Sam Smith

Hourly Wage: 10

Hours Worked: 40

Withholding Exemptions: 0

Marital Status (S = Single, M = Married): M

Paycheck for john Lee

Gross Income:                           $      400.00

less Medicare Tax:                     $        5.80

less Social Security Tax:              $       24.80

less FICA Tax:                         $       30.60

less Federal Income Tax Withheld:      $       17.45

Net Income:                             $      351.95

-----------------------------------------------------

Employee Name:(type 'Quit' to end program)

Sally Smith

Hourly Wage: 25

Hours Worked: 50

Withholding Exemptions: 2

Marital Status (S = Single, M = Married): M

Paycheck for Sally Smith

Gross Income:                           $     1375.00

less Medicare Tax:                     $       19.94

less Social Security Tax:              $       85.25

less FICA Tax:                         $      105.19

less Federal Income Tax Withheld:      $       98.85

Net Income:                             $     1170.97

-----------------------------------------------------

Employee Name:(type 'Quit' to end program)

Quit

Grand Paycheck Totals--------------------------------

-----------------------------------------------------

Total Gross Income:                     $     1775.00

Total Medicare Tax:                    $       25.74

Total Social Security Tax:              $      110.05

Total FICA Tax:                         $      135.79

Total Income Tax Withheld:              $      116.30

Total Net Income:                       $     1522.92

-----------------------------------------------------

-----------------------------------------------------

Solutions

Expert Solution

PROGRAM:

Please find below the javaDoc style commented program:

package test;

/**

* The program implements the method to calculate the

* pay stub for employee by asking the user

* to enter employee details

* Paystub will show calculation for individual

* as well as totals of pays at the end

* when user quits the program *

*

* @author Student Name

* @version 1.0

* @since   2020-7-11

*/

import java.util.Scanner;

import java.text.DecimalFormat;

public class PaystubAA {

     static Scanner scObj = new Scanner(System.in);

     static DecimalFormat format = new DecimalFormat("#.##");

     public static void main(String[] args) {

          String Name;

          float hourlyWage;

          int hoursWorked, withHoldings;

          char maritalStatus;

          double grossPay,socialSecurityTax,medicareTax, FICATax, netIncome, federalTax;

          double totalEmployee = 0, totalGross = 0, totalScoailSecurityTax = 0, totalMedicareTax = 0, TotalFICATax = 0,totalNetIncome=0, totalFederalTax = 0;

          System.out.print("Enter Employee Name (type 'Quit' to end program): ");

          Name= ReadStringFromUser();

          while(!Name.toUpperCase().equals("QUIT")) {

              System.out.print("Hourly Wage: ");

              hourlyWage = ReadFloatFromUser();

              System.out.print("Hours worked: ");

              hoursWorked = scObj.nextInt();

              System.out.print("Withholding Exemptions(between 0 to 10): ");

              withHoldings= scObj.nextInt();

              while(withHoldings<0 || withHoldings>10)

              {

                   System.out.print("Withholding exemption to be between 1 to 10. Enter again:");

                   withHoldings= scObj.nextInt();

              }            

              scObj.nextLine();

              System.out.print("Marital Status(S= Single, M=Married): ");

              maritalStatus = scObj.next().charAt(0);

             

              grossPay=calcGrossPay(hourlyWage, hoursWorked);

              medicareTax=grossPay* (.0145);

              socialSecurityTax = grossPay*(.062);

              FICATax = medicareTax+socialSecurityTax;

              federalTax= FederalTax(grossPay, maritalStatus, withHoldings);

              netIncome=grossPay-FICATax-federalTax;

             

              System.out.println("Paycheck for "+Name);

              System.out.println("Gross Income:\t\t\t\t $"+format.format(grossPay)+

              "\nless Medicare Tax:\t\t\t $"+format.format(medicareTax)+

              "\nless Social Security Tax:\t\t $"+format.format(socialSecurityTax)+

              "\nless FICA Tax:\t\t\t\t: $" + format.format(FICATax)+

              "\nless Federal Income Tax Withheld:\t$"+format.format(federalTax)+

              "\nNet Income:\t\t\t\t$"+format.format(netIncome));

             

              totalEmployee++;

              totalFederalTax= totalFederalTax+federalTax;

              totalMedicareTax=totalMedicareTax+medicareTax;

               totalScoailSecurityTax=totalScoailSecurityTax+socialSecurityTax;

              totalGross= totalGross+grossPay;

              totalNetIncome= totalNetIncome+netIncome;

              TotalFICATax=TotalFICATax+FICATax;

              scObj.nextLine();

              System.out.println("\n-----------------------------------------------\n");

              System.out.print("Enter next employee Name (type 'Quit' to end program): ");

              Name= ReadStringFromUser();

             

          }

          System.out.println("Grand PayCheck Totals: ");

          System.out.println("\n***********************\n");

          System.out.println("Total Gross Income:\t\t\t $"+format.format(totalGross)+

                   "\nTotal Medicare Tax:\t\t\t $"+format.format(totalMedicareTax)+

                   "\nTotal Social Security Tax:\t\t $"+format.format(totalScoailSecurityTax)+

                   "\nTotal FICA Tax:\t\t\t\t $" + format.format(TotalFICATax)+

                   "\nTotal Federal Income Tax Withheld:\t $"+format.format(totalFederalTax)+

                   "\nTotal Net Income:\t\t\t$"+format.format(totalNetIncome));

         

     }

     /**

        * This method is used to calculate the federal tax. .

        * @param grossPay: This is grossPay passed to this method

        * @param maritalStatus: This is maritalStatus passed to this method from calling method

        * @param withholdings: This is withholdings numbers passed to this method

        * @return double This returns calculated ferderal tax based on the params passed in it.

        */

     private static double FederalTax(double grossPay, char maritalStatus, int withHoldings) {

          grossPay=grossPay- (withHoldings * 55.77);

          double tax=0;

          if(maritalStatus == 'S') {

              if(grossPay>=51 && grossPay<500.99)

                   tax=(grossPay-51)*.10;

              else if(grossPay>=501 && grossPay<2500.99) {

                   tax=45+ (grossPay-500)*.15;System.out.println("tax is: "+tax);}

              else if(grossPay>=2501 && grossPay<=5000)

                   tax=345+ (grossPay-2500)*.20;

              else

                   tax=845+ (grossPay-5000)* .25;

          }

          else {

              if(grossPay>=51 && grossPay<500.99)

                   tax=(grossPay-51)*.05;

              else if(grossPay>=501 && grossPay<2500.99)

                   tax=45+ (grossPay-500)*.10;

              else if(grossPay>=2501 && grossPay<=5000)

                   tax=345+ (grossPay-2500)*.15;

              else

                   tax=845+ (grossPay-5000)* .20;

          }

         

          return tax;

     }

    

     /**

        * This method is used to calculate the gross pay.

        * if hours are less than or equal to 40, pay is hour multiplied by hourly wags

        * if hours are more than 40, employee gets one and half time pay for hours

        * more than 40

        * @param hourlyRate: value of hoursly rate

        * @param hoursWorked: total hours worked

        * @return double calculation of gross pay based on the total hours

        */

     private static double calcGrossPay(float hourlyWage, int hoursWorked) {

          if(hoursWorked <=40)

              return hourlyWage*hoursWorked;

          else

              return ((hourlyWage*40)+ ((hourlyWage*1.5)*(hoursWorked-40)));

         

     }

     /**

        * This method is used to read the float numbers from user .

        * @param none: nothing will be passed to this method

        * @return float This returns entered float value by user at runtime

        */

     private static float ReadFloatFromUser() {

          float inputFloat = scObj.nextFloat();

          return inputFloat;

     }

     /**

        * This method is used to read the String inputs from user .

        * @param none: nothing will be passed to this method

        * @return float This returns entered string by user at runtime

        */

     private static String ReadStringFromUser() {

          String enteredString = scObj.nextLine();

          return enteredString;

     }

}

SCREENSHOT:

OUTPUT:

**Please note that calculations are as per given guideline and the output sample in question have some errors in calculations. The program output will calculate the correct values. Thanks!!!


Related Solutions

write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
Write a Java program to move data among variables: (1) define 4 int variable pos1, pos2,...
Write a Java program to move data among variables: (1) define 4 int variable pos1, pos2, pos3, pos4, input 4 integer numbers from console and assign them to these variables; display message in the following format: “pos1=a-number; pos2=a-number; pos3=a-number; pos4=a-number”. “anumber” is replaced with real number. (2) Left shift data in these variables: for each variable to get the value of the successive variable, with pos4 getting pos1's value. Display pos1, pos2, pos3, and pos4 (3) Right shift data in...
How to write IO program in java?
How to write IO program in java?
Write a program in JAVA to create the move set of a Pokémon, and save that...
Write a program in JAVA to create the move set of a Pokémon, and save that move set to a file. This program should do the following: Ask for the pokemon’s name. Ask for the name, min damage, and max damage of 4 different moves. Write the move set data into a file with the pokemon’s name as the filename. The format of the output file is up to you, but keep it as simple as possible
how to create BANKACCOUNT program using Arrays in JAVA.
how to create BANKACCOUNT program using Arrays in JAVA.
Goals Practice conditional statements Description Write a program to simulate a menu driven calculator that performs...
Goals Practice conditional statements Description Write a program to simulate a menu driven calculator that performs basic arithmetic operations (add, subtract, multiply and divide). The calculator accepts two numbers and an operator from user in a given format: For example: Input: 6.3 / 3 Output: 2.1 Create a Calculator class that has a method to choose the right mathematical operation based on the entered operator using switch case. It should then call a corresponding method to perform the operation. In...
JAVA Exercise BasketBall Bar Chart Write a program that allows you to create a bar chart...
JAVA Exercise BasketBall Bar Chart Write a program that allows you to create a bar chart for the active members of a basketball team during a game. (Recall: there are only 5 active players on the court per team in a standard basketball game.) Your program should do the following tasks: • Prompt the user to store the first name of the five players • Prompt the user to enter the points scored by each player a. Use a while...
Write a Java program to create an array of a specific size (which is an input...
Write a Java program to create an array of a specific size (which is an input from the user) and fill it with random numbers between 1 and 100. Then sort the array and count how many of these numbers are originally at sorted position. Display that original array, the sorted array, and the count (number of elements originally at sorted position).
Write a program in java that does the following: Create a StudentRecord class that keeps the...
Write a program in java that does the following: Create a StudentRecord class that keeps the following information for a student: first name (String), last name (String), and balance (integer). Provide proper constructor, setter and getter methods. Read the student information (one student per line) from the input file “csc272input.txt”. The information in the file is listed below. You can use it to generate the input file yourself, or use the original input file that is available alone with this...
Write the program in java Write a program that does basic encrypting of text. You will...
Write the program in java Write a program that does basic encrypting of text. You will ask the user the filename of a text file which contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT