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. Any help will be greatly apreciated.
Here is my latest code... - // Payroll program that calculates an employee's weekly pay.
-
-
import java.util.Scanner; // program uses class Scanner
-
-
class EmployeeData {
-
EmployeeData(String newName, float newHourlyRate, float newHoursWorked) {
-
name = newName; hourlyRate = newHourlyRate; hoursWorked = newHoursWorked;
-
}
-
-
public String getName() { return name; }
-
public float getWeeklyPay() { return hourlyRate * hoursWorked; }
-
-
private String name;
-
private float hourlyRate, hoursWorked;
-
} // end of EmployeeData class
-
-
public class Payroll3
-
{
-
private String EmployeeData; // employee information for this Payroll
-
-
// main method begins execution of java application
-
public static void main( String args[] )
-
{
-
boolean stop = false; // This flag will control whether we exit the loop below
-
-
// Loop until user types "stop" as the employee name:
-
while (!stop)
-
{
-
// create scanner to obtain input from command window
-
Scanner input = new Scanner ( System.in );
-
-
System.out.println(); // outputs a blank line
-
System.out.print( "Please enter the employee name or 'stop' to end program: " ); // prompt
-
String empName = input.nextLine(); // read employee name
-
-
if ( empName.compareTo("stop") == 0) // Check whether user indicated to stop program
-
{
-
System.out.println( "Program ended." );
-
stop = true;
-
}
-
else
-
{
-
// User did not indicate to stop, so continue reading info for this iteration:
-
EmployeeData employee;
-
float hourlyRate; // first number to multiply
-
float hoursWorked; // second number to multiply
-
float weeklyPay; // product of hourlyRate and hoursWorked
-
-
System.out.print( "Please enter hourly rate: $" ); // prompt
-
hourlyRate = input.nextFloat(); // read hourly rate from user
-
while (hourlyRate <= 0) // prompt until a positive value is entered
-
{
-
System.out.print( "Hourly rate must be a positive value. " +
-
"Please enter the hourly rate again: $" ); // prompt for positive value for hourly rate
-
hourlyRate = input.nextFloat(); // read hourly rate again
-
}
-
-
System.out.print( "Please enter hours worked: " ); // prompt
-
hoursWorked = input.nextFloat(); // read number of hours worked from user
-
while (hoursWorked <= 0) // prompt until a positive value is entered
-
{
-
System.out.print( "Hours worked must be a positive value. " +
-
"Please enter the hours worked again: " ); // prompt for positive value for hours worked
-
hoursWorked = input.nextFloat(); // read hours worked again
-
}
-
-
employee = new EmployeeData(empName, hourlyRate, hoursWorked);
-
///weeklyPay = hourlyRate * hoursWorked; // multiply
-
-
System.out.print( employee.getName() ); // display employee name
-
System.out.printf( "'s weekly pay is: $%,.2f\n", employee.getWeeklyPay() ); // display weekly pay
-
-
}
-
}
-
-
} // end method main
-
-
} // end class Payroll3
10 7622 DeMan 1,806
Top Contributor
What appears to be the problem, the EmployeeData class seems to do everything you have asked....
I assume you need help with the main body of the program, but could you please specify what is the problem you are having....
I think we might be in the same class... I am trying to figure these things out too... I will try to help you as I get them...
To store the Employers's data, you neen an ArrayList not a String. -
-
// Payroll program that calculates an employee's weekly pay.
-
import java.util.*; // program uses class Scanner
-
class EmployeeData {
-
EmployeeData(String newName, float newHourlyRate, float newHoursWorked) {
-
name = newName;
-
hourlyRate = newHourlyRate;
-
hoursWorked = newHoursWorked;
-
}
-
public String getName() {
-
return name;
-
}
-
public float getWeeklyPay() {
-
return hourlyRate * hoursWorked;
-
}
-
private String name;
-
private float hourlyRate, hoursWorked;
-
} // end of EmployeeData class
-
public class Payroll3
-
{
-
-
// main method begins execution of java application
-
public static void main( String args[] )
-
{
-
ArrayList employees = new ArrayList(); // employee information for this Payroll you need to be able to store many employees
-
boolean stop = false; // This flag will control whether we exit the loop below
-
// Loop until user types "stop" as the employee name:
-
while (!stop)
-
{
-
// create scanner to obtain input from command window
-
Scanner input = new Scanner ( System.in );
-
System.out.println(); // outputs a blank line
-
System.out.print( "Please enter the employee name or 'stop' to end program: " ); // prompt
-
String empName = input.nextLine(); // read employee name
-
if ( empName.compareTo("stop") == 0) // Check whether user indicated to stop program
-
{
-
System.out.println( "Program ended." );
-
stop = true;
-
}
-
else
-
{
-
// User did not indicate to stop, so continue reading info for this iteration:
-
EmployeeData employee;
-
float hourlyRate; // first number to multiply
-
float hoursWorked; // second number to multiply
-
float weeklyPay; // product of hourlyRate and hoursWorked
-
System.out.print( "Please enter hourly rate: $" ); // prompt
-
hourlyRate = input.nextFloat(); // read hourly rate from user
-
while (hourlyRate <= 0) // prompt until a positive value is entered
-
{
-
System.out.print( "Hourly rate must be a positive value. " +
-
"Please enter the hourly rate again: $" ); // prompt for positive value for hourly rate
-
hourlyRate = input.nextFloat(); // read hourly rate again
-
}
-
System.out.print( "Please enter hours worked: " ); // prompt
-
hoursWorked = input.nextFloat(); // read number of hours worked from user
-
while (hoursWorked <= 0) // prompt until a positive value is entered
-
{
-
System.out.print( "Hours worked must be a positive value. " +
-
"Please enter the hours worked again: " ); // prompt for positive value for hours worked
-
hoursWorked = input.nextFloat(); // read hours worked again
-
}
-
employee = new EmployeeData(empName, hourlyRate, hoursWorked);
-
///weeklyPay = hourlyRate * hoursWorked; // multiply
-
System.out.print( employee.getName() ); // display employee name
-
System.out.printf( "'s weekly pay is: $%,.2f\n", employee.getWeeklyPay() ); // display weekly pay
-
employees.add(employee);
-
}
-
}
-
//You can do additional stuff with the employees here
-
-
} // end method main
-
} // end class Payroll3
-
To store the Employers's data, you neen an ArrayList not a String. -
-
// Payroll program that calculates an employee's weekly pay.
-
import java.util.*; // program uses class Scanner
-
class EmployeeData {
-
EmployeeData(String newName, float newHourlyRate, float newHoursWorked) {
-
name = newName;
-
hourlyRate = newHourlyRate;
-
hoursWorked = newHoursWorked;
-
}
-
public String getName() {
-
return name;
-
}
-
public float getWeeklyPay() {
-
return hourlyRate * hoursWorked;
-
}
-
private String name;
-
private float hourlyRate, hoursWorked;
-
} // end of EmployeeData class
-
public class Payroll3
-
{
-
-
// main method begins execution of java application
-
public static void main( String args[] )
-
{
-
ArrayList employees = new ArrayList(); // employee information for this Payroll you need to be able to store many employees
-
boolean stop = false; // This flag will control whether we exit the loop below
-
// Loop until user types "stop" as the employee name:
-
while (!stop)
-
{
-
// create scanner to obtain input from command window
-
Scanner input = new Scanner ( System.in );
-
System.out.println(); // outputs a blank line
-
System.out.print( "Please enter the employee name or 'stop' to end program: " ); // prompt
-
String empName = input.nextLine(); // read employee name
-
if ( empName.compareTo("stop") == 0) // Check whether user indicated to stop program
-
{
-
System.out.println( "Program ended." );
-
stop = true;
-
}
-
else
-
{
-
// User did not indicate to stop, so continue reading info for this iteration:
-
EmployeeData employee;
-
float hourlyRate; // first number to multiply
-
float hoursWorked; // second number to multiply
-
float weeklyPay; // product of hourlyRate and hoursWorked
-
System.out.print( "Please enter hourly rate: $" ); // prompt
-
hourlyRate = input.nextFloat(); // read hourly rate from user
-
while (hourlyRate <= 0) // prompt until a positive value is entered
-
{
-
System.out.print( "Hourly rate must be a positive value. " +
-
"Please enter the hourly rate again: $" ); // prompt for positive value for hourly rate
-
hourlyRate = input.nextFloat(); // read hourly rate again
-
}
-
System.out.print( "Please enter hours worked: " ); // prompt
-
hoursWorked = input.nextFloat(); // read number of hours worked from user
-
while (hoursWorked <= 0) // prompt until a positive value is entered
-
{
-
System.out.print( "Hours worked must be a positive value. " +
-
"Please enter the hours worked again: " ); // prompt for positive value for hours worked
-
hoursWorked = input.nextFloat(); // read hours worked again
-
}
-
employee = new EmployeeData(empName, hourlyRate, hoursWorked);
-
///weeklyPay = hourlyRate * hoursWorked; // multiply
-
System.out.print( employee.getName() ); // display employee name
-
System.out.printf( "'s weekly pay is: $%,.2f\n", employee.getWeeklyPay() ); // display weekly pay
-
employees.add(employee);
-
}
-
}
-
//You can do additional stuff with the employees here
-
-
} // end method main
-
} // end class Payroll3
-
Thank you, but this outputs a note of "uses unchecked or unsafe operations".
I think we might be in the same class... I am trying to figure these things out too... I will try to help you as I get them...
Thank you. I wasn't doing too bad in this class until this past week. I was ill for three days and I guess it threw me off track more than I ever imagined.
What appears to be the problem, the EmployeeData class seems to do everything you have asked....
I assume you need help with the main body of the program, but could you please specify what is the problem you are having....
You are correct. I thought I had a problem here, but after going through it once again, step by step, the code works as it should. I hate to admit it, but my husband must be right when he tells me that I make things harder than what they really are. I apologize for wasting everyone's time here.
Thank you.
You are correct. I thought I had a problem here, but after going through it once again, step by step, the code works as it should. I hate to admit it, but my husband must be right when he tells me that I make things harder than what they really are. I apologize for wasting everyone's time here.
Thank you.
No you did not waste anyone's time
No you did not waste anyone's time
Thank you.
Ok so I’m in this same class and your posts really helped allot. I just want to know how do I not plagiarize the work that was done by someone else if we all have to write the same application? I’m about to turn mine in and it’s almost a copy/paste of the code above even though I wrote it all out.
Ganon11 3,652
Recognized Expert Specialist
Ok so I’m in this same class and your posts really helped allot. I just want to know how do I not plagiarize the work that was done by someone else if we all have to write the same application? I’m about to turn mine in and it’s almost a copy/paste of the code above even though I wrote it all out.
If you've written the code by yourself, I wouldn't be terribly worried about it. Some simple programs have just about 1 solution, and every code solving that problem will look similar, if not identical. As long as your code works and you know you've written it yourself and thought the whole process through thoroughly, I think you'll be fine.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Randi |
last post by:
Hi,
Looking for some help with this payrool project I have for class. This is
what the instructor asks for so far. I have it working without errors but
am getting some funky numbers. I am not...
|
by: zexx |
last post by:
Need some advise....
Payroll program Access97. Payroll is printed then posted to a hx table thro'
a query with the payroll calculations that freeze that payroll's numbers for
that period.
The...
|
by: cheungs7 |
last post by:
Hi all,
Wondering whether you can anyone help me. We have Sage Payroll (and
accounting/payroll software), which has a MS Access database where the data
is stored.
Now I want to access the...
|
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...
|
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...
| |
by: John Sitka |
last post by:
Hi,
There are four pay types
standard
shiftpremium
doubletime
doubletimepremium
each hour a person books can be one of these types
|
by: jbailey006 |
last post by:
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...
|
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...
|
by: aureao4 |
last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |