Payroll Program 3 question
I have been beeting my head aginst a wall :frusty:
i have to come up with a payroll program
that produces
Input name: Tim
input time : 40 hours
input rate: $23
Produce: Tim made (sum of time * rate) $920
Input name: Tim
input time : 40 hours
input rate: $23
Produce: Tim made ((sum of time * rate)+previous answer) $1840
but i cannot get it to add in the previous answer
Code:
import java.util.Scanner;
class Week4PR
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("The program determines the employees weekly pay.");
System.out.println("Please enter the requested information, Thanks!");
do{
System.out.print( "Please enter the employees name or stop to quit:" );
String PersonName = input.next();
if(PersonName.compareTo("stop") == 0)
{
System.out.println();
System.out.println("*** Thank You for choosing this program, Good Bye! ***");
System.out.println();
break;
}
double Hours;
double Rate;
double sum;
System.out.print( "Enter hours worked this week: " );
Hours = input.nextDouble();
while (Hours < 0)
{
System.out.print("Enter a positive number of hours worked:");
Hours = input.nextDouble();}
System.out.print( "Enter your hourly pay rate: " );
Rate= input.nextDouble();
while (Rate < 0)
{
System.out.print("Enter a positive number for pay rate:");
Rate = input.nextDouble(); }
System.out.printf( "Payroll for %s\n",PersonName );
sum = Hours * Rate;
System.out.printf( "Weekly pay is %.2f", sum );
System.out.println();
} while(true);
}
}
class Employee
{
private String name;
private double Rate;
private double Hours;
public Employee ()
{
name = "";
Rate = 0.0;
Hours = 0.0;
}
public Employee(String employeenameIn, double hourlyRateInDollarsIn, double hoursWorkedInWeekIn) {
name = employeenameIn;
Rate = hourlyRateInDollarsIn;
Hours = hoursWorkedInWeekIn;
}
public void setName (String name) {
this.name = name;
}
public String getName () {
return name;
}
public void setpayRate (double payRate) {
this.Rate = payRate;
}
public double getpayRate () {
return Rate;
}
public void sethoursWorked (double hoursWorked) {
this.Hours = hoursWorked;
}
public double gethoursWorked () {
return Hours;
}
public double getearnedPay () {
return Rate * Hours;
}
} // end class Employee
I know that i need to add something but i do not know what, any help would be greatly appreciated.
Re: Payroll Program 3 question
Can you add comments to the program's output showing what is wrong with it and what the output should be?
Re: Payroll Program 3 question
Here is the current output:
The program determines the employees weekly pay.
Please enter the requested information, Thanks!
Please enter the employees name or stop to quit:tim
Enter hours worked this week: 40
Enter your hourly pay rate: 23
Payroll for tim
Weekly pay is 920.00
Please enter the employees name or stop to quit:tim
Enter hours worked this week: 40
Enter your hourly pay rate: 23
Payroll for tim
Weekly pay is 920.00
Please enter the employees name or stop to quit:
I need the output to add previous entries
Re: Payroll Program 3 question
Quote:
I need the output to add previous entries
Please edit the output and show what you want the output to look like. I have no idea how and where you want the extra data displayed.
Re: Payroll Program 3 question
Oops sorry i seem to be still beeting my head aginst the wall :frusty:
The program determines the employees weekly pay.
Please enter the requested information, Thanks!
Please enter the employees name or stop to quit:tim
Enter hours worked this week: 40
Enter your hourly pay rate: 23
Payroll for tim
Weekly pay is 920.00
Please enter the employees name or stop to quit:tim
Enter hours worked this week: 40
Enter your hourly pay rate: 23
Payroll for tim
Weekly pay is 920.00
Total for Pay tim is $1840
Please enter the employees name or stop to quit:tim
Enter hours worked this week: 40
Enter your hourly pay rate: 23
Payroll for tim
Weekly pay is 920.00
Total for Pay tim is $2760
Please enter the employees name or stop to quit:
i want the application to add all the previous weeks and (be able to swich between employees, such as tim, mary..... and add to each accordinly this part may not be necesssary but would be helpful if possible with my current code)
Re: Payroll Program 3 question
Quote:
Total for Pay tim is $1840
Is this the line you want added to the program?
The way you add together a list of numbers is to use a variable to accumulate the total in. Initialize it to 0 and then add to it the next value as you get it.
int var = 0;
begin the loop
compute a value
var = var + value <<< add the new value to the accumulation
// var now has the sum of all the previous values
end loop
Re: Payroll Program 3 question
Well you have an employee class on the bottom there, but you never use it. I can already see how using that Class can help you store information about the employee's payment history :) Think hard. If you really have no idea then come back to us, and I'll be happy to nudge you in the right direction :)
Re: Payroll Program 3 question
I understand that a simple var could be used to add, but i am needing to recall the data from the class, and i am not sure of how to do that could you please provide me with a sample that i can work off, PPPllllease:(-:
Re: Payroll Program 3 question
Quote:
am needing to recall the data from the class,
What variable from what class?
As christopherx said, you are not using the Employee class at all.
What is the purpose of the class?
Where and how do you plan to use it?
Re: Payroll Program 3 question
I need the program to recall the person name and pay and have it add each the same name is used, also if a different name is used i want it to display that person's name and pay,
such as :
tim 920
tim 1840 ....
but if mary is entered
mary 450
mary 900
and if tim is entered again
tim 2760
and if mary is entered
mary 1350
displayed as:
"name" has made a total of $"total"
tim has made a total of $2760
Re: Payroll Program 3 question
Quote:
I need the program to recall the person name and pay
Where is the person's data to be stored? You have a class that looks like a good place.
When you get done gathering the data for a person you should create an Employee object with all that data in it.
Then you will need some kind of container to store the data for each person, link an array or arraylist.
Re: Payroll Program 3 question
Well that explains it i have not gotten that far in the class, thanks tho, i am going to shoot the teacher now
i thought that i had it worng:(punch):