Click to See Complete Forum and Search --> : Help with method


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

dlorde
October 16th, 2008, 06:53 PM
So what is your question? What are you stuck on? What don't you understand?

You might find this helpful: How To Ask A Smart Question (http://www.catb.org/~esr/faqs/smart-questions.html).

Judge a man by his questions, rather than his answers...
Voltaire

donnelg
October 16th, 2008, 07:15 PM
Thanks for the quick responds.

I'm having trouble invoking my method. How do get the following method to work in my main method. Hopefully I'm not confusing you.

public static double grossPay( double nHrsWrkd, double hrlyRate) {
if (hrlyRate <= 40) {
grossPay = hrlyRate * nHrsWrkd;
}
else {
grossPay = 40* hrlyRate + (hour - 40)*(rate*1.5);
}
System.out.print("Gross pay is");

donnelg
October 16th, 2008, 07:19 PM
Thanks for the link...My question was a bit generic. I'm new to programming, I'm trying to learn the correct terminology. Thanks again for the link

Norm
October 16th, 2008, 09:18 PM
How do get the following method to work in my main method

Are you asking how to call a method from another method?
If the method returns a value:

var = method(args);

You can replace the names with what you need/have in your program.

If that is not your question, please explain.

dlorde
October 17th, 2008, 05:23 AM
Thanks for the link...My question was a bit generic. I'm new to programming, I'm trying to learn the correct terminology. Thanks again for the linkIt's not so much the terminology as the lack of clear information. If you are "having trouble invoking" a method, explain what the trouble is - is it not compiling? Is it crashing when you run it? If so, post up the full error message text and stack trace. Is it running but not doing what you expected? If so, explain what you expected to happen and what is actually happening instead.

It's not rocket science, it's just a matter of providing all the relevant information.

Programming is an explanatory activity...
R. Harper