In the midst of writing the code for my
java program, i have seem to taken a misturn somewhere. Any advise or sugestions on what i can do to correct this is much needed. It works good until i get to the employee class near the bottom.
import java.util.Scanner; // This program uses class Scanner
public class Payroll {
public Payroll() {
//create a scanner object to obtain input from command window
Scanner input = new Scanner(System.in);
String employeeName = ""; //input employee name
double hourlyWage;
double hoursWorked;
double weeklyPay;
// loop until the user enters 'stop' as the name of the employee.
do {
// Get Employee Name
System.out.print("Enter Name of Employee:");
employeeName = input.next();
// if the employee name is 'stop', then exit the loop.
if (employeeName.equals("stop")) {
break;
}
// ask for hourly wage
System.out.print("Enter hourly Wage:");
hourlyWage = input.nextDouble();
// require that the hourly wage is a non-negative
while (hourlyWage < 0.0)
{
System.out.print("Hourly wage must be a positive number. Please enter a positive hourly wage:");//prompt
hourlyWage = input.nextDouble();
input.nextLine();
}
// ask the hours worked
System.out.print("Enter hours worked:");
hoursWorked = input.nextDouble();
// require that hours worked be a non-negative number
while (hoursWorked < 0.0)
{
System.out.print("Hours worked must be a positive number. Please enter a positive number of hours:");//prompt
hoursWorked=input.nextDouble();
input.nextLine();
}
weeklyPay = hourlyWage * hoursWorked;
System.out.printf("The employee, %s, was paid $ %.2f this week.\n\n", employeeName, weeklyPay);
} while (true);
}
} public static void main(String args[]) {
new Payroll();
} //end method main
//end class Payroll
public class Employee {
public Employee() {
String name;
int hoursworked;
int hourlywage;
int weeklyPay;
public Employee(String name, int hours, int rate) {
this.name = name;
this.hoursworked = hours;
hourlywage = rate;
computeWeeklyPay();
}
private void computeWeeklyPay() {
weeklyPay = hoursworked * hourlywage;
}
public int getWeeklyPay() {
return weeklyPay;
}
;