hi i created this program for a university project but i don't know how to fix the problem. here is the program:
// class
public class Employee
{
private double Wage = 0, pay = 0;
private double hoursWork;
public void setWage(double aWage)
{
Wage = aWage;
}
public void calcPay()
{
if (hoursWork <= 40)
{
pay = hoursWork * Wage;
}
if ( hoursWork > 40)
{
pay = (40 * Wage) + ((hoursWork - 40) * (1.5 * Wage));
}
}
public double getPay()
{
return pay;
}
}
// testClass
import java.util.Scanner;
public class testEmployee
{
public static void main(String args[])
{
Scanner input = new Scanner (System.in);
Employee emp = new Employee();
System.out.print("Enter hourly wage: ");
double wage = input.nextDouble();
emp.setWage(wage);
System.out.print("enter the employee name(X to quit): " );
String yourName = input.nextLine();
System.out.print("Enter hours worked: ");
double hours = input.nextDouble();
emp.calcPay();
System.out.println();
String exit = "X" ;
while (!(yourName.equals (exit)))
{
System.out.println(yourName);
System.out.println("Pay: " + emp.getPay());
System.out.println("Enter new name(X to quit)");
yourName = input.nextLine();
System.out.print("Enter new hours worked ");
hours = input.nextDouble();
emp.calcPay();
}
}
}
the output i get is:
Enter hourly wage: 100
enter the employee name(X to quit): Enter hours worked:
the program doesn't allow me to enter the name. it just prints the hours worked right next to it