Netlinkaccess - All about Payroll Services and Accounting
*Home>>>Payroll Program

Need help adding to exsisting java code to modify a program. Please help!!?


Here is what I have to do:
Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate.


I will post the code in 2 seperate comments as it will not all fit in here.
I need to use my exsisting code, just make modifcation to it.

import java.util.Scanner;

public class Payroll2
{
public static void main (String args[])
{
double rate, total; // Local variables to hold the rate and total salary
int hours; // Local variable to hold the amount of hours worked
String name; // Local variable to hold the employee's name

Scanner input = new Scanner(System.in); // create a new instance of a Scanner object type

do // Begin main loop - continue until name equals stop
{
System.out.printf("Please enter the employee name (enter stop to quit): ");
name = input.next();

if (name.equalsIgnoreCase("stop")) // compare the value in the string to the literal string "stop"
System.out.printf("\nProgram termination requested.\n");
else
{
do // repeat these steps until the user enters a rate above 0...
{
System.out.printf("Please enter %s's hourly rate of pay: $", name);

Didn't change up your program to terribly much, just added the extra Employee object at the end and slightly modified your original program to use it.

import java.util.Scanner;

public class Payroll2 {

public static void main (String args[]){
double rate; // Local variables to hold the rate and total salary
int hours; // Local variable to hold the amount of hours worked
String name; // Local variable to hold the employee's name
Scanner input = new Scanner(System.in); // create a new instance of a Scanner object type

do { // Begin main loop - continue until name equals stop
System.out.printf("Please enter the employee name (enter stop to quit): ");
name = input.next();

if (name.equalsIgnoreCase("stop"))
// compare the value in the string to the literal string "stop"
System.out.printf("\nProgram termination requested.\n");
else {
do { // repeat these steps until the user enters a rate above 0...
System.out.printf("Please enter %s's hourly rate of pay: $", name);
rate = input.nextDouble();
if (rate <= 0)
System.out.printf("\n *** Hourly rate of pay can only be entered in POSITIVE numbers! Try again!\n");
} while (rate <= 0);
do { // repeat these steps until the user enters more than 0 hours...
System.out.printf("Please enter %s's amount of hours worked: ", name);
hours = input.nextInt();
if (hours <= 0)
System.out.printf("\n *** Hours worked can only be entered in POSITIVE numbers! Try again!\n");
} while (hours <= 0);
Employee employee = new Employee(name, hours, rate);
System.out.printf("\nIf %s gets paid $%.2f per hour, for %d hours of work...........", employee.getName(), employee.getRate(), employee.getHours());
System.out.printf("\n%s's weekly gross pay will be $%.2f\n\n", employee.getName(), employee.getTotal());
}
} while (!(name.equalsIgnoreCase("stop")));
// User entered stop for the name, end loop.
}
}





public class Employee {

private String name;
private int hours;
private double rate;

/**
* Employee object for use with the payroll program.
* @param name Name of the Employee
* @param hours Hours the employee worked
* @param rate Rate of pay for the Employee
*/
public Employee(String name, int hours, double rate){
// constructor for an employee object
this.name = name;
this.hours = hours;
this.rate = rate;
}

public Employee(String name, double rate){
// overload of the constructor to set a default 40 hour workweek
this(name, 40, rate);
}

// next 3 methods are generic getter methods

public String getName(){
return name;
}

public int getHours(){
return hours;
}

public double getRate(){
return rate;
}

// getter method to calculate and return the total

public double getTotal(){
return (hours * rate);
}
}

Tags
  Payroll Card   Payroll Tax   Payroll Accounting   Online Payroll   Adp Payroll   Payroll Program   Payroll Software   Payroll System   Payroll Processing   Payroll Services
Related information
  • C++ Program IST240 PSU Help NEEDED!!?

    // Bart Simpsons writing int main() { return bart_simpson_writing_on_blackboard(); } int bart_simpson_writing_on_blackboard() { cout << "I will do my own homework."; c...

  • Indiana has ended a program that put a chaplain position on the payroll. Do you find paying clergy acceptable?

    absolutely not. church & state are supposed to be sepperate. i dont go to church and i understand that some people feel they need it, but they can pay for it themselves. im not gonna pay for th...

  • I need to find and easier way to do payroll for about 150 people done by hand,what's a good program to us?

    Millennium Payroll system is good, and very user friendly. The tech support was always great, and it worked with the time clock system. Payroll used to take me three days- after we got this, it t...

  • Im looking for a home/small business program to keep track of invoices, payroll, etc...any help?

    Quickbooks

    ...
  • How many people are on the government payroll at all levels? How many oversee programs like abortion funding?

    Federal : 16,769,427,957 ...

  • Anyone working in payroll?

    You can set up a spreadsheet in Excel to calculate your payroll. You would need to set up different columbs . One for Gross pay, one for Federal withheld, one for State withheld, one for Medicare, ...

  • What kind of tax program will....?

    First see link below for what form to file. It could be a Form 1065 in addition to 1040. Once you figure that out go buy the programs that do those forms. ...

  • Reoord/Database Program?

    You can try Microsoft Access if it is on your computer. That's what I use for stuff.

    ...
  •  

    Categories--Copyright/IP Policy--Contact Webmaster