donnelg
October 16th, 2008, 05:07 PM
Hello all. This my first time posted here. I' m new to Java and find it very interesting..Anyways, I have task to write the follow program. But I'm having some trouble figuring my next step.
Problem:
write a program that calculates their weekly pay. The program main prompts you for the first and last name of the employee in addition to the number of hours that employee worked for the week. The program prints out the employee’s name in addition to the gross pay, taxes withheld from the gross and the net pay (gross pay - taxes withheld). Assume the following:
Hourly base pay rate = Specified by the user
O/T rate in excess of 40 hours = Time and a half (1.5 * rate specified by the user )
Tax schedule = 15% of the first $300.00,
20% of the amount over $300.00 and less than $450.00,
25% of the amount over $450.00
Be sure to define constants for key parameters of the program that do not change. Your program must also contain two methods:
• static float calcGross( float nHrsWrkd, float hrlyRate )
• static float calcTaxes( float grossPay )
The first method calculates the gross pay based on the input number of hours worked and hourly rate. The second calculates the taxes based on the input gross pay. Neither method prints anything to the console.
In addition, the program main must continuously prompt the user to continue. Your output should appear as shown below. Please pay special attention to all formatting components.
Please enter the employee's first name - Mary
Now please enter the employee's last name - Jo
Enter the number of hours Mary Jo worked this week - 30
Finally, please enter the hourly rate earned by Mary Jo - 10
Employee Name - Mary Jo
Hours Worked - 30.00
Hourly Rate - 10.00
Gross Pay - $300.00
Taxes Withheld - $45.00
Net Pay - $255.00
Do you wish to continue ( 0 = No ; 1 = Yes ) - 1
Please enter the employee's first name - Bobby
Now please enter the employee's last name - Sue
Enter the number of hours Bobby Sue worked this week - 40
Finally, please enter the hourly rate earned by Bobby Sue - 12.5
Employee Name - Bobby Sue
Hours Worked - 40.00
Hourly Rate - 12.50
Gross Pay - $500.00
Taxes Withheld - $87.50
Net Pay - $412.50
Do you wish to continue ( 0 = No ; 1 = Yes ) - 1
Please enter the employee's first name - Kathy
Now please enter the employee's last name - Lee
Enter the number of hours Kathy Lee worked this week - 52.5
Finally, please enter the hourly rate earned by Kathy Lee - 15
Employee Name - Kathy Lee
Hours Worked - 52.50
Hourly Rate - 15.00
Gross Pay - $881.25
Taxes Withheld - $182.81
Net Pay - $698.44
Do you wish to continue ( 0 = No ; 1 = Yes ) - 0
Good Bye!!
So far, this is what I have.
import java.util.Scanner;
public class ComputeWeeklyPay2 {
// Main method
public static void main(String[] args) {
/** Create input scanner */
Scanner input = new Scanner(System.in);
byte pick = 1;
do{
// Prompt user to enter first name
System.out.print("Please enter the employee's first name - ");
String firstname = input.next();
// Prompt user to enter last name
System.out.print("Now please enter employee's last name - ");
String lastname = input.next();
// Prompt user to enter employee weekly hours
System.out.println("Enter the number of hours " + firstname + " "
+ lastname + " worked this week - ");
double weeklyhours = input.nextDouble();
// Prompt user to enter employee hourly rate
System.out.println("Finally, please enter the hourly rate earned by "
+ firstname + " " + lastname + " - ");
double rate = input.nextDouble();
// Prompt user to choose
System.out.print("\nDon you wish to continue ( 0 = No; 1 = Yes) ? - ");
pick = input.nextByte();
}while (pick == 1);
System.out.print("Good Bye!");
}
}
Any help would be greatly appreciated
Problem:
write a program that calculates their weekly pay. The program main prompts you for the first and last name of the employee in addition to the number of hours that employee worked for the week. The program prints out the employee’s name in addition to the gross pay, taxes withheld from the gross and the net pay (gross pay - taxes withheld). Assume the following:
Hourly base pay rate = Specified by the user
O/T rate in excess of 40 hours = Time and a half (1.5 * rate specified by the user )
Tax schedule = 15% of the first $300.00,
20% of the amount over $300.00 and less than $450.00,
25% of the amount over $450.00
Be sure to define constants for key parameters of the program that do not change. Your program must also contain two methods:
• static float calcGross( float nHrsWrkd, float hrlyRate )
• static float calcTaxes( float grossPay )
The first method calculates the gross pay based on the input number of hours worked and hourly rate. The second calculates the taxes based on the input gross pay. Neither method prints anything to the console.
In addition, the program main must continuously prompt the user to continue. Your output should appear as shown below. Please pay special attention to all formatting components.
Please enter the employee's first name - Mary
Now please enter the employee's last name - Jo
Enter the number of hours Mary Jo worked this week - 30
Finally, please enter the hourly rate earned by Mary Jo - 10
Employee Name - Mary Jo
Hours Worked - 30.00
Hourly Rate - 10.00
Gross Pay - $300.00
Taxes Withheld - $45.00
Net Pay - $255.00
Do you wish to continue ( 0 = No ; 1 = Yes ) - 1
Please enter the employee's first name - Bobby
Now please enter the employee's last name - Sue
Enter the number of hours Bobby Sue worked this week - 40
Finally, please enter the hourly rate earned by Bobby Sue - 12.5
Employee Name - Bobby Sue
Hours Worked - 40.00
Hourly Rate - 12.50
Gross Pay - $500.00
Taxes Withheld - $87.50
Net Pay - $412.50
Do you wish to continue ( 0 = No ; 1 = Yes ) - 1
Please enter the employee's first name - Kathy
Now please enter the employee's last name - Lee
Enter the number of hours Kathy Lee worked this week - 52.5
Finally, please enter the hourly rate earned by Kathy Lee - 15
Employee Name - Kathy Lee
Hours Worked - 52.50
Hourly Rate - 15.00
Gross Pay - $881.25
Taxes Withheld - $182.81
Net Pay - $698.44
Do you wish to continue ( 0 = No ; 1 = Yes ) - 0
Good Bye!!
So far, this is what I have.
import java.util.Scanner;
public class ComputeWeeklyPay2 {
// Main method
public static void main(String[] args) {
/** Create input scanner */
Scanner input = new Scanner(System.in);
byte pick = 1;
do{
// Prompt user to enter first name
System.out.print("Please enter the employee's first name - ");
String firstname = input.next();
// Prompt user to enter last name
System.out.print("Now please enter employee's last name - ");
String lastname = input.next();
// Prompt user to enter employee weekly hours
System.out.println("Enter the number of hours " + firstname + " "
+ lastname + " worked this week - ");
double weeklyhours = input.nextDouble();
// Prompt user to enter employee hourly rate
System.out.println("Finally, please enter the hourly rate earned by "
+ firstname + " " + lastname + " - ");
double rate = input.nextDouble();
// Prompt user to choose
System.out.print("\nDon you wish to continue ( 0 = No; 1 = Yes) ? - ");
pick = input.nextByte();
}while (pick == 1);
System.out.print("Good Bye!");
}
}
Any help would be greatly appreciated