hi all,
If you think this thread looks familiar, you have probably seen it before. Thousands of students come to this forum every year looking for help because, lets face it, its much easier to see code and ask questions than to learn from some old textbook.
So here I am, I need some help with my payroll program and anyone that knows more than me is welcome to answer (which should be almost anyone on here) Here is my payroll code and below that I will list the new instructions and my progress. Thank you.
import java.util.Scanner;
public class Payroll
{
public static void main( String args[] )
{
Scanner input = new Scanner ( System.in );
float number1;
float number2;
float sum;
System.out.println();
System.out.print("Payroll Calculation Program\nPlease type STOP to end program");
System.out.println();
System.out.println();
System.out.println();
System.out.print("Enter Employee Name:");
String empName = input.nextLine();
while ( !empName.equalsIgnoreCase("stop") )
{
System.out.printf( "Enter Hourly Rate for %s: $",empName );
number1 = input.nextFloat();
while (number1 < 0.00) {
System.out.print("Please re-enter using positive numbers only: $");
number1 = input.nextFloat();
}
System.out.print ( "Enter Hours Worked: ");
number2 = input.nextFloat();
while (number2 < 0.00) {
System.out.print ("Please re-enter using positive numbers only: ");
number2 = input.nextFloat();
}
sum = number1 * number2;
System.out.printf ("%s's weekly pay is:$%.2f\n",empName,sum);
System.out.println();
input.nextLine();
System.out.print("Enter Employee Name:");
empName = input.nextLine();
}
}
}
I need to modify the program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. I also need to use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay.
So here is what I have done, aside from building the program above. I have begun to build what I think is a constructor within my payroll.java file, and it looks like this
empName = new Employee (number1,number2, sum);
and I have also begun work on my employee.java file which looks like this
public class Employee {
float number1;
float number2;
float sum;
Employee (float number1, float number2, float sum) {
number1 = ;
Yah, I know none of this is probably correct, so please MTV, pimp my....no wait, fix my code!
Thank you guys (sorry, got to through in a few jokes)