I\'m trying to fix this buggy program. I was told something is an int and it sho
ID: 3556069 • Letter: I
Question
I'm trying to fix this buggy program. I was told something is an int and it should be a double. Here is the code.
public class MainPayroll {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
String input; //to hold user's input
int number; //to hold a number
Payroll employeeData = new Payroll();
//get info
input = JOptionPane.showInputDialog("What is the employee's name?");
employeeData.setName(input);
//System.out.println(employeeData.getName()); //test output
input = JOptionPane.showInputDialog("What is the employee's ID Number?");
employeeData.setID(input);
//System.out.println(employeeData.getID()); //test output
input = JOptionPane.showInputDialog("What is the employee's hourly pay rate?");
number = (input);
employeeData.setPay(number);
//System.out.println(employeeData.getPay()); //test output
input = JOptionPane.showInputDialog("How many hours did the employee work?");
number = (input);
employeeData.setHours(number);
//System.out.println(employeeData.getHours()); //test output
JOptionPane.showMessageDialog(null, "The employee's gross pay is "+ employeeData.getTotalPay());
}
}
public class Payroll
{
private String name; //The employee's name
private String idNumber; //The employee's ID Number
private double hourlyPay; //The employee's hourly pay
private double hoursWorked; // The number of hours the employee worked
public Payroll()
{
name = ("");
idNumber = ("");
hourlyPay = 0.0;
hoursWorked = 0.0;
}
public void setName(String employee)
{
name = employee;
}
public void setID(String num)
{
idNumber = num;
}
public void setPay(double hourly)
{
hourlyPay = hourly;
}
public void setHours(double hours)
{
hoursWorked = hours;
}
public String getName()
{
return name;
}
public String getID()
{
return idNumber;
}
public double getPay()
{
return hourlyPay;
}
public double getHours()
{
return hoursWorked; }
public double getTotalPay()
{
return hourlyPay * hoursWorked;
}
}
Computer Science
Explanation / Answer
import javax.swing.*; public class MainPayroll { /** * @param args the command line arguments */ public static void main(String[] args) { String input; //to hold user's input int number; //to hold a number Payroll employeeData = new Payroll(); //get info input = JOptionPane.showInputDialog("What is the employee's name?"); employeeData.setName(input); //System.out.println(employeeData.getName()); //test output input = JOptionPane.showInputDialog("What is the employee's ID Number?"); employeeData.setID(input); //System.out.println(employeeData.getID()); //test output input = JOptionPane.showInputDialog("What is the employee's hourly pay rate?"); number = Integer.parseInt((input)); employeeData.setPay(number); //System.out.println(employeeData.getPay()); //test output input = JOptionPane.showInputDialog("How many hours did the employee work?"); number = Integer.parseInt((input)); employeeData.setHours(number); //System.out.println(employeeData.getHours()); //test output JOptionPane.showMessageDialog(null, "The employee's gross pay is "+ employeeData.getTotalPay()); } } public class Payroll { private String name; //The employee's name private String idNumber; //The employee's ID Number private double hourlyPay; //The employee's hourly pay private double hoursWorked; // The number of hours the employee worked public Payroll() { name = (""); idNumber = (""); hourlyPay = 0.0; hoursWorked = 0.0; } public void setName(String employee) { name = employee; } public void setID(String num) { idNumber = num; } public void setPay(double hourly) { hourlyPay = hourly; } public void setHours(double hours) { hoursWorked = hours; } public String getName() { return name; } public String getID() { return idNumber; } public double getPay() { return hourlyPay; } public double getHours() { return hoursWorked; } public double getTotalPay() { return hourlyPay * hoursWorked; } }