473,583 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with payroll program.

3 New Member
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.Scann er;


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.prin t( "Please enter employee name or stop to exit program: " );
String name = input.nextLine( );

while (name != "stop"){

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

hourlyrate = input.nextDoubl e();

if (hourlyrate >= 0){

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

if (hourlyrate <= 0){

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

hourlyrate = input.nextDoubl e();

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

hours = input.nextDoubl e();

if (hours >=0){

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

if (hours <=0){

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

hours = input.nextDoubl e();

pay = hourlyrate * hours;

input.nextLine( );

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




// Display employee information


} // end method main

} // end class Calculate
Jan 30 '07 #1
5 11617
r035198x
13,262 MVP
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.Scann er;


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.prin t( "Please enter employee name or stop to exit program: " );
String name = input.nextLine( );

while (name != "stop"){

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

hourlyrate = input.nextDoubl e();

if (hourlyrate >= 0){

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

if (hourlyrate <= 0){

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

hourlyrate = input.nextDoubl e();

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

hours = input.nextDoubl e();

if (hours >=0){

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

if (hours <=0){

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

hours = input.nextDoubl e();

pay = hourlyrate * hours;

input.nextLine( );

System.out.prin tf("%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
jbailey006
3 New Member
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.prin tf( "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.Scann er;


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.prin tln( "Please enter employee name or stop to exit program: " );
String name = input.nextLine( );
aEmployee.setEm ployeeName( name );
System.out.prin tln();
aEmployee.displ ayMessage();

while (name != "stop"){

System.out.prin tln( "Program Ended" );

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

hourlyrate = input.nextDoubl e();

if (hourlyrate >= 0){

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

if (hourlyrate <= 0){

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

hourlyrate = input.nextDoubl e();

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

hours = input.nextDoubl e();

if (hours >=0){

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

if (hours <=0){

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

hours = input.nextDoubl e();

pay = hourlyrate * hours;

input.nextLine( );

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




// Display employee information


} // end method main

} // end class Calculate
Feb 1 '07 #3
r035198x
13,262 MVP
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.prin tf( "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.Scann er;


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.prin tln( "Please enter employee name or stop to exit program: " );
String name = input.nextLine( );
aEmployee.setEm ployeeName( name );
System.out.prin tln();
aEmployee.displ ayMessage();

while (name != "stop"){

System.out.prin tln( "Program Ended" );

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

hourlyrate = input.nextDoubl e();

if (hourlyrate >= 0){

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

if (hourlyrate <= 0){

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

hourlyrate = input.nextDoubl e();

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

hours = input.nextDoubl e();

if (hours >=0){

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

if (hours <=0){

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

hours = input.nextDoubl e();

pay = hourlyrate * hours;

input.nextLine( );

System.out.prin tf("%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
jbailey006
3 New Member
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 MVP
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
1577
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 name from the Payroll it is made INACTIVE. This is to ensure that his/her name does not appear in subsequent payroll.
8
2163
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 table. Here are the specifics as well as I can explain it: I have the following table fields: EmployerID Group Payroll Yes/No
2
5211
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, but I cant figure out how to put it together. Here's the description of whats needed to be done: Write a program that generates an Employee Payroll....
2
1432
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 assistance. Don't forget to include the full address of whereever I can get the book to buy, please. Thank you.
0
1239
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 dependents, martial status and a dollar amount which is a deduction for the company 401k plan. part one of the program allows one to add employee to the...
10
7632
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 employee information, and a method within that class to calculate the weekly pay. It seems that the more I read into this, the more confused I get....
1
1609
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 February 2007 Payroll. How will the user close January payroll and then start that of February? I cannot figure out how to write the Program for...
2
1205
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 module also is notworking properly, and how to make my time tick. Below is my coding, thankyou for any help. #include<stdio.h> #include<stdlib.h>...
3
2352
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
7888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8314
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7922
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8185
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3811
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1416
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.