473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need help with payroll program.

I am trying to add the following information to a payroll program I am working on for assignment. 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. Her's what I have.

// Calculate.java
// Calculate weekly pay.

import java.util.Scanner;


public class calculate
{
// main method begins execution of java application
public static void main( String args[] )
{
Scanner input = new Scanner ( System.in );
double hourlyrate;
double hours;
double pay;

//boolean stop = false; // Exit the loop below

//loop until user enters "stop" as the employee name:

// while (!stop)

// create scanner to obtain data from user


System.out.print( "Please enter employee name or stop to exit program: " );
String name = input.nextLine();

while (name != "stop"){

System.out.println("Please enter hourly rate: $" );}

hourlyrate = input.nextDouble();

if (hourlyrate >= 0){

System.out.println("hourly rate is: " + hourlyrate);}

if (hourlyrate <= 0){

System.out.println("Hourly rate must be a positive value. " + "Please enter the hourly rate again: $");}

hourlyrate = input.nextDouble();

System.out.println("Please enter hours worked: ");

hours = input.nextDouble();

if (hours >=0){

System.out.println("hours is: " + hours);}

if (hours <=0){

System.out.println("Hours worked must be a positive value. " + "Please enter the hours worked again: ");}

hours = input.nextDouble();

pay = hourlyrate * hours;

input.nextLine();

System.out.printf("%s pay is $ %.2f\n",name, pay);




// Display employee information


} // end method main

} // end class Calculate
Jan 30 '07 #1
5 11601
r035198x
13,262 8TB
I am trying to add the following information to a payroll program I am working on for assignment. 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. Her's what I have.

// Calculate.java
// Calculate weekly pay.

import java.util.Scanner;


public class calculate
{
// main method begins execution of java application
public static void main( String args[] )
{
Scanner input = new Scanner ( System.in );
double hourlyrate;
double hours;
double pay;

//boolean stop = false; // Exit the loop below

//loop until user enters "stop" as the employee name:

// while (!stop)

// create scanner to obtain data from user


System.out.print( "Please enter employee name or stop to exit program: " );
String name = input.nextLine();

while (name != "stop"){

System.out.println("Please enter hourly rate: $" );}

hourlyrate = input.nextDouble();

if (hourlyrate >= 0){

System.out.println("hourly rate is: " + hourlyrate);}

if (hourlyrate <= 0){

System.out.println("Hourly rate must be a positive value. " + "Please enter the hourly rate again: $");}

hourlyrate = input.nextDouble();

System.out.println("Please enter hours worked: ");

hours = input.nextDouble();

if (hours >=0){

System.out.println("hours is: " + hours);}

if (hours <=0){

System.out.println("Hours worked must be a positive value. " + "Please enter the hours worked again: ");}

hours = input.nextDouble();

pay = hourlyrate * hours;

input.nextLine();

System.out.printf("%s pay is $ %.2f\n",name, pay);




// Display employee information


} // end method main

} // end class Calculate
Hey, the question says you should write the Employee class. Write code for that and post it and we will be able to help where you are wrong.
Jan 30 '07 #2
Hey, the question says you should write the Employee class. Write code for that and post it and we will be able to help where you are wrong.
public class Employee
{

private String employeeName; // name for wages
private double hourlyrate;
private double hours;

// method to set the name
public void setEmployeeName( String name )
{
employeeName = name; // store name
} // end method setEmployeeName

// method to retrieve the employee name
public String getEmployeeName()
{
return employeeName;
} // end method getEmployeeName

// display employee name
public void displayMessage()
{
// this statement calls getEmployeeName
System.out.printf( "Employee's name is: %s\n",
getEmployeeName() );
} // end method displayMessage
public void setHourlyrate( double hourlyrate )
{
hourlyrate = hourlyrate;
}

public double getHourlyrate(){
return hourlyrate;
}
public void setHours( double hours )
{
hours = hours;
}

public double getHours(){
return hours;
}
public double getPay(){
return hourlyrate * hours;
}

} // end class Employee

// Calculate.java
// Calculate weekly pay.

import java.util.Scanner;


public class calculate
{
// main method begins execution of java application
public static void main( String args[] )
{
Scanner input = new Scanner ( System.in );

double hourlyrate;
double hours;
double pay;

//boolean stop = false; // Exit the loop below

//loop until user enters "stop" as the employee name:

// while (!stop)

// create scanner to obtain data from user

Employee aEmployee = new Employee();

System.out.println( "Please enter employee name or stop to exit program: " );
String name = input.nextLine();
aEmployee.setEmployeeName( name );
System.out.println();
aEmployee.displayMessage();

while (name != "stop"){

System.out.println( "Program Ended" );

System.out.println("Please enter hourly rate: $" );}

hourlyrate = input.nextDouble();

if (hourlyrate >= 0){

System.out.println("hourly rate is: " + hourlyrate);}

if (hourlyrate <= 0){

System.out.println("Hourly rate must be a positive value. " + "Please enter the hourly rate again: $");}

hourlyrate = input.nextDouble();

System.out.println("Please enter hours worked: ");

hours = input.nextDouble();

if (hours >=0){

System.out.println("hours is: " + hours);}

if (hours <=0){

System.out.println("Hours worked must be a positive value. " + "Please enter the hours worked again: ");}

hours = input.nextDouble();

pay = hourlyrate * hours;

input.nextLine();

System.out.printf("%s pay is $ %.2f\n",name, pay);




// Display employee information


} // end method main

} // end class Calculate
Feb 1 '07 #3
r035198x
13,262 8TB
public class Employee
{

private String employeeName; // name for wages
private double hourlyrate;
private double hours;

// method to set the name
public void setEmployeeName( String name )
{
employeeName = name; // store name
} // end method setEmployeeName

// method to retrieve the employee name
public String getEmployeeName()
{
return employeeName;
} // end method getEmployeeName

// display employee name
public void displayMessage()
{
// this statement calls getEmployeeName
System.out.printf( "Employee's name is: %s\n",
getEmployeeName() );
} // end method displayMessage
public void setHourlyrate( double hourlyrate )
{
hourlyrate = hourlyrate;
}

public double getHourlyrate(){
return hourlyrate;
}
public void setHours( double hours )
{
hours = hours;
}

public double getHours(){
return hours;
}
public double getPay(){
return hourlyrate * hours;
}

} // end class Employee

// Calculate.java
// Calculate weekly pay.

import java.util.Scanner;


public class calculate
{
// main method begins execution of java application
public static void main( String args[] )
{
Scanner input = new Scanner ( System.in );

double hourlyrate;
double hours;
double pay;

//boolean stop = false; // Exit the loop below

//loop until user enters "stop" as the employee name:

// while (!stop)

// create scanner to obtain data from user

Employee aEmployee = new Employee();

System.out.println( "Please enter employee name or stop to exit program: " );
String name = input.nextLine();
aEmployee.setEmployeeName( name );
System.out.println();
aEmployee.displayMessage();

while (name != "stop"){

System.out.println( "Program Ended" );

System.out.println("Please enter hourly rate: $" );}

hourlyrate = input.nextDouble();

if (hourlyrate >= 0){

System.out.println("hourly rate is: " + hourlyrate);}

if (hourlyrate <= 0){

System.out.println("Hourly rate must be a positive value. " + "Please enter the hourly rate again: $");}

hourlyrate = input.nextDouble();

System.out.println("Please enter hours worked: ");

hours = input.nextDouble();

if (hours >=0){

System.out.println("hours is: " + hours);}

if (hours <=0){

System.out.println("Hours worked must be a positive value. " + "Please enter the hours worked again: ");}

hours = input.nextDouble();

pay = hourlyrate * hours;

input.nextLine();

System.out.printf("%s pay is $ %.2f\n",name, pay);




// Display employee information


} // end method main

} // end class Calculate
Going in the right direction but I'm still not interested yet. How do we create the Epmloyees if you haven't added a construcor for that.

Add two constructors, indent the code and post it using code tags.
Feb 1 '07 #4
Going in the right direction but I'm still not interested yet. How do we create the Epmloyees if you haven't added a construcor for that.

Add two constructors, indent the code and post it using code tags.
I think I figured it out. I have another project involving an Inventory program. I can see from previous post that it's a popular topic.
Feb 1 '07 #5
r035198x
13,262 8TB
I think I figured it out. I have another project involving an Inventory program. I can see from previous post that it's a popular topic.
Good. I always like to see people find the solutions themselves. The inventory thing seems to be the thing of the moment.
Feb 2 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Akinyemi | last post by:
I am developing a payroll program.. The data generated will be saved in an Access Database. I want a situation whereby when an employee leaves the organization or retires, instead of deleting his...
8
by: narpet | last post by:
Hello all. I have a table in Access that has a check box as one of the fields. I want to write a query or code that will check or uncheck that box based on conditions met by other fields in the...
2
by: varusnyc | last post by:
Hello, Im having really hard time writing an Employee Payroll program that uses functions to read data from file then send all data to another file. I managed to construct some pieces of the code,...
2
by: Akinyemi | last post by:
I have been trying to develop a Payroll Program, but Iam having difficuty in doing so. Please can any member recomend any good Visual Basic 6 book on Payroll Programming? I shall appreciate your...
0
by: RENEE | last post by:
I Need help writing a program that will process payroll for small company with 26 employess, needs to store all employee name in sequential file along with address info, pay rate, number of...
10
by: ycg0771 | last post by:
I'm trying to modify the following 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...
1
by: Akinyemi | last post by:
I have almost finished writing my Payroll Program. But I am wondering how the program can be used for different months. For example, after, say January 2007 Payroll, the user would want to prepare...
2
by: optimum | last post by:
I have develop a new coding using C, with some problem where the search and update functions are working but when I enter a record which is not available it getting me to another record, my delete...
3
allingame
by: allingame | last post by:
Need help with append and delete duplicates I have tables namely 1)emp, 2)time and 3)payroll TABLE emp ssn text U]PK name text
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.