Question

JAVA Programming . Description: For an unknown number of employees: prompt and receive payroll data; calculate...

JAVA Programming .

Description:

For an unknown number of employees: prompt and receive payroll data; calculate gross pay, taxes owed, and net pay; and display a pay stub.

Input :

Prompt and receive input from the user for the following: 

/// Employee’s First and Last Name 

/// Hours Worked 

/// Pay Rate 

/// Overtime Rate Multiplier

** For the Employee’s First and Last Name:  Both data items must be read in one prompting into one variable (e.g. “Sam Jones”).  Validate to only allow alphabetic characters.  Do not validate for upper/lower case.  Re-prompt the user until the input is valid.

** For Hours Worked:  Represents the hours worked in one week.  Validate to only allow numbers in the range 0 – 100.00  Allow for up to two decimal places (e.g. 40.75).  Round to nearest cent if the user enters more than two decimal places.  Re-prompt the user until the input is valid.

** For Pay Rate:  Represents the amount earned per one hour of work.  Validate to only allow numbers in the range 9.00 – 25.00 or blank (not given).  Allow for up to two decimal places (e.g. 10.50).  Round to nearest cent if the user enters more than two decimal places.  Default value is 9.00  Dollar sign should not be entered by the user.  Re-prompt the user until the input is valid.

** For Overtime Rate Multiplier:  Represents a Pay Rate Multiplier.  Must be >= 1.0 or blank (not given).  Allow for one decimal place (e.g. 1.5).  Round if the user enters more than one decimal place.  Default value is no pay rate increase for hours > 40. In other words, hours > 40 earn wages at the same pay rate as hours <= 40. Another way of thinking of it is an overtime rate multiplier of 1.  Re-prompt the user until the input is valid. 2 v2.0 Use a While or Do-While Loop to continue prompting for employee data until a sentinel value is detected. You may not use a For-Loop. I leave the sentinel value implementation details for you to decide.

Processing:

Calculate Gross Pay as follows: 

/// Gross Pay = Hours Worked * Pay Rate 

/// If Pay Rate is not supplied, then use the default value.

/// if OverTime Multiplier is not supplied, then Gross Pay = Hours Worked * Pay Rate.

/// if OverTime Multiplier is supplied, the Gross Pay = Hours Worked (<= 40) * Pay Rate + Hours Worked (> 40) * Pay Rate * OverTime Multiplier

/// Calculate Taxes as follows:  Taxes = Gross Pay * Tax Rate 

Use the following Tax Rate Table:

Gross Pay:    Tax Rate:

<= $520    10%

> $520 and <= $680    15%

> $680 and <= $840 20%

> $840 25%

/// Calculate Net Pay as follows:  Net Pay = Gross Pay – Taxes .

Output :

After prompting, receiving and processing the data items, display the employee’s name, Gross Pay, Taxes owed, and Net Pay.

For Employee’s Name, format as proper case with only one space between the first and last names.

For Taxes, display the appropriate percentage based upon the Tax Rate Table after the word “Taxes” in the output results; for example, Taxes (15%).

Monetary values must be rounded to the nearest cent using standard rounding rules. For example, $3.409 will displayed as $3.41. $3.404 will displayed as $3.40.

Monetary values must display the dollar sign directly next to the monetary value (e.g. $304.50).

Note:

to do this, you will need to: 

Import the java.text.NumberFormat class 

Use the NumberFormat.getCurrencyInstance() method 

Use the format() method 

Do a little research for this Monetary values must be right justified.

Each employee’s information must be separated by a line of asterisks.

//// Write the following methods exactly as shown using the listed method and variable names. Method getGross is overloaded and overloading is required. Name Purpose Return Type Return Value Parameters getGross To calculate the Gross Pay using workHours and default payRate double Amount of Gross Pay double workHours getGross To calculate the Gross Pay using workHours and payRate double Amount of Gross Pay double workHours, double payRate getGross To calculate the Gross Pay using workHours and payRate; using overTimeMultiplier if applicable double Amount of Gross Pay double workHours, double payRate, double overTimeMultiplier getTaxes To calculate the Taxes using grossPay double Amount of Taxes double grossPay getNet To calculate the Net Pay using grossPay and taxes double Amount of Net Pay double grossPay, double taxes printPayStub To display the Pay Stub data Void None String empName, double grossPay, double taxes, double netPay .

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

/*
* The java program that prompts user to enter first name
* last name, hours worked and pay rate and then
* find the gross amount,tax rate and the net amount on console
* window.
* */
//EmployeePaycheck.java
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
public class EmployeePaycheck
{
   public static void main(String[] args)
   {
       //create a Scanner class object
       Scanner console=new Scanner(System.in);

       String firstName;
       String lastName;
       double overTimeMultiplier=1.5;

       int workHours;
       double payRate;
       double gross=0;
       double net=0;

       //Read first name and last name
       System.out.printf("Enter first name: ");
       firstName=console.nextLine();
       System.out.printf("Enter last name: ");
       lastName=console.nextLine();

       //read work hours
       do
       {
           System.out.printf("Enter work hours[0-100]:");
           workHours=Integer.parseInt(console.nextLine());
           if(workHours<0 || workHours>100)
               System.out.println("Invalid work hours!");          
       }while(workHours<0 || workHours>100);
      
       //read pay rate
       do
       {
           System.out.printf("Enter pay rate[9-25]:");
           payRate=Integer.parseInt(console.nextLine());
           if(payRate<9 || payRate>25)
               System.out.println("Invalid pay rate!");          
       }while(payRate<9 || payRate>25);

       if(workHours>40)
           //call getGross method
           gross=getGross(workHours,payRate,overTimeMultiplier);
       else
           //call getGross method
           gross=getGross(workHours,payRate);

       //call getNet method
       net=getNet(gross);

       NumberFormat numberFormat =
               NumberFormat.getCurrencyInstance(new Locale("en", "US"));
      
       //Print the gross ,tax and net amount
       System.out.println("Gross : "+numberFormat.format(gross));
       System.out.println("Taxes(%) : "+getTaxes(gross));
       System.out.println("Net : "+numberFormat.format(net));

   }
   /*Method that takes gross and return tax rate*/
   private static double getTaxes(double gross)
   {
       double taxRate=0;
       if(gross<=520)
           taxRate=10;
       else if(gross>520 && gross<=680)
           taxRate=15;
       else if(gross>680 && gross<=840)
           taxRate=20;
       else
           taxRate=25;
      
       return taxRate;
   }

   /*Method that takes gross amount and then
   * find the net pay amount*/
   private static double getNet(double gross)
   {
       return gross-gross*getTaxes(gross)/100.0;
   }
   /*Overloaded method that takes hours and payrate
   * and returns the gross amount*/
   private static double getGross(int workHours, double payRate)
   {
       return workHours*payRate;  
   }
   /*Overloaded method that takes hours , payrate and overtime
   * multiplier value
   * and returns the gross amount*/
   private static double getGross(int workHours, double payRate, double overTimeMultiplier)
   {  
       return 40*payRate+(workHours-40)*payRate*overTimeMultiplier;
   }
}

Sample Output:

Enter first name: Sam
Enter last name: Jones
Enter work hours[0-100]:60
Enter pay rate[9-25]:25
Gross : $1,750.00
Taxes(%) : 25.0
Net : $1,312.50

Add a comment
Answer #2

try out this code for payroll example:

public class Payrollcalc{

private:

String name;

double hoursWorked;

double hourly payRate;

static final double TAX_RATE1=0.1;//<=$520

static final double TAX_RATE2=0.15;//>$520<=680

static final double TAX_RATE3=0.2;//>680<=$840

static final double TAX_RATE4=0.4;//>$840;

public:

Payrollcalc()();

Payrollcalc(String n,double hw,double,hr)

{

this.name=n;

this.hoursworked=hw;

this.hourlyperrate=hp;

}

double grosspay(double hourlyrate,double hrsworked)

{

double grosspay=hourlyrate*hrsworked;

return grosspay;

}

double tax(double gross)

{

if(gross<=520.0) return TAX_RATE1*gross;

if(gross>520.0 && gross<=680.0)return TAX_RATE2*gross;

if(gross>680.0 && gross<=840.0) return TAX_RATE3*gross;

if(gross>840.0) return TAX_RATE4*gross;

}

String getName(){return name;}

void setName(String name){this.name=name;}

double gethoursworked(){return hoursworked;}

void sethoursworked(double hoursworked){this.hoursworked=hoursworked;}

void gethourlypayrate(){return hourlypayrate;}

void set hourlypayrate(double hourlypayrate){this.hourltpayrate=hourlypayrate;}

}

import java.util.*;

public class Payroledr

{

public static void main(String args[])

{

Scanner input=new Scanner(System.in);

Payrollcalc data=new Payrolecalc();

System.put.println("Enter your name:");

data.setname(input.next());

System.out.println("No. of hours worked:");

data.sethoursworked(Double.parseDouble(input.next());

System.out.println("Enter hourly pay rate:");

data.sethourlypayrate(Doub;e.parseDouble(input.next());

double grossamt=data.grosspay(data.gethourlypayrate().data.gethoursworked());

System.out.println("Name:"+data.getname());

System.out.println("Hoursworked"+data.gethoursworked));

System.out.println("hours pay rate"+data.gethourlypayrate());

System.out.println("grosspay"+data.grossamount());

Syste.out.println("Deductions");

System.out.println("total dedcutions $"+dada.tax(grossamount));

System.out.println("Netpay$"+grossamount-data.tax(grossamount));

input.close();}

}

HOpe this helps .please compile for any typing errors.

regards.

Add a comment
Know the answer?
Add Answer to:
JAVA Programming . Description: For an unknown number of employees: prompt and receive payroll data; calculate...
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
  • Program Description: Write the pseudocode for a program that will calculate and display an employee’s gross...

    Program Description: Write the pseudocode for a program that will calculate and display an employee’s gross pay. Input the number of hours an employee worked for each of the 5 days of the week. Add them all up to get his hours worked for the week. Weekly Pay is calculated by adding an employee’s normal pay plus any overtime pay. Normal hours are paid at $10/hr. Any over time is paid at $15/hr. Any hours over 40 are considered overtime....

  • 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 =...

  • Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

    Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any...

  • I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime)...

    I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...

  • Write a program Java that gets an employee’s number, pay rate, and the number of hours...

    Write a program Java that gets an employee’s number, pay rate, and the number of hours worked in a week from a clerk. The program is then to validate the pay rate and the hours worked data and, if valid, compute the employee’s weekly pay and print it along with the input data. Company rules prohibit working more than 60 hours per week or having an hourly rate of more than $25.00/hour. Any data with these values should generate an...

  • 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...

  • Program is to be written In C++, The output should look like the screen shot. It...

    Program is to be written In C++, The output should look like the screen shot. It should allow the user to continue to ask the user to enter all employee ID's until done and then prompt the user to enter the hours and pay rate for each employee ID. Please help:( Can you please run the program to make sure the output is just like the screenshot please? It needs to have the output that is in the screenshot provided,...

  • Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All...

    Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All rights reserved. // #include<iostream> #include<fstream> #include<cstdlib> #include<regex> #include <iomanip> using namespace std; float grossPay(float hrsWorked, float payrate); float grossPay(float hrsWorked, float payrate){ return hrsWorked*payrate;       } int main(){    //opening an output file ifstream outFile("Employee.txt", ios::in); //Read variables string depId,emp_num,firstName,lastName,email,hrs_worked,pay_rate,ch="y";    //Regex patterns regex integerPattern("(\\+|-)?[[:digit:]]+"); regex...

  • Using the code below (C++), add a struct with only 1 vector #include #include #include //...

    Using the code below (C++), add a struct with only 1 vector #include #include #include // Needed to define vectors using namespace std; int main() { vector hours; // hours is an empty vector vector payRate; // payRate is an empty vector int numEmployees; // The number of employees int index; // Loop counter // Get the number of employees. cout << "How many employees do you have? "; cin >> numEmployees; // Input the payroll data. cout << "Enter...

  • Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main()...

    Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it...

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