Question
Why I cannot run this programms ? Please explain. 1. import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import javax.swing.JOptionPane; public class Payroll { private
Why I cannot run this programms ? Please explain.
1.
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import javax.swing.JOptionPane; public class Payroll { private static ArrayList 2. import java.util.GregorianCalendar; // Java's calendar class. public class Person { // Attributes: private String lastName; private String firstName; private GregorianCalendar birthday; private String gender; // Overloaded Constructors: public Person() { this("", "", "", ""); } public Person(String ln, String fn, String cal, String gen) { setLastName(ln); setFirstName(fn); setBirthday(cal); setGender(gen); } // Mutators: public void setLastName(String lastName) { this.lastName = lastName; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setBirthday(String bday) { bday = bday.trim(); int month = Integer.parseInt(bday.substring(0, bday.indexOf('/')))-1; bday = bday.substring(bday.indexOf('/')+1, bday.length()); int day = Integer.parseInt(bday.substring(0, bday.indexOf('/'))); bday = bday.substring(bday.indexOf('/')+1, bday.length()); int year = Integer.parseInt(bday); birthday = new GregorianCalendar(year, month, day); } public void setGender(String gender) { this.gender = gender; } // Accessors: public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public String getBirthday() { String result = ""+(birthday.get(GregorianCalendar.MONTH)+1); result += "/"+birthday.get(GregorianCalendar.DAY_OF_MONTH); result += "/"+birthday.get(GregorianCalendar.YEAR); return result; } public String getGender() { return gender; } public String toString() { String result = "Last Name: "+getLastName(); result += " First Name: "+getFirstName(); result += " Gender: "+getGender(); result += " Birthday: "+getBirthday(); return result; } } 3. import javax.swing.JOptionPane; public class InputValid { public static String getString(String prompt, String title, String errorMessage) { boolean invalid; String result = ""; do { invalid = false; try { result = JOptionPane.showInputDialog(null, prompt, title, JOptionPane.QUESTION_MESSAGE); if (result.length() == 0) throw new Exception("Input is blank."); } catch (Exception e) { invalid = true; JOptionPane.showMessageDialog(null, e.getMessage()+" "+errorMessage, "ERROR", JOptionPane.ERROR_MESSAGE); } } while (invalid); return result; } public static int getInt(String prompt, String title, String errorMessage) { boolean invalid; String input = ""; int result=0; do { invalid = false; try { input = JOptionPane.showInputDialog(null, prompt, title, JOptionPane.QUESTION_MESSAGE); if (input.length() == 0) throw new Exception("Input is blank."); result = Integer.parseInt(input); } catch (Exception e) { invalid = true; JOptionPane.showMessageDialog(null, e.getMessage()+" "+errorMessage, "ERROR", JOptionPane.ERROR_MESSAGE); } } while (invalid); return result; } public static double getDouble(String prompt, String title, String errorMessage) { boolean invalid; String input = ""; double result=0.0; do { invalid = false; try { input = JOptionPane.showInputDialog(null, prompt, title, JOptionPane.QUESTION_MESSAGE); if (input.length() == 0) throw new Exception("Input is blank."); result = Double.parseDouble(input); } catch (Exception e) { invalid = true; JOptionPane.showMessageDialog(null, e.getMessage()+" "+errorMessage, "ERROR", JOptionPane.ERROR_MESSAGE); } } while (invalid); return result; } } 4. public class Employee extends Person { // Attributes: private int employeeId; private int hours; private double payRate; private double wages; // Overloaded Constructors: public Employee() { super(); //calling methods to default values setEmployeeId(0); setHours(0); setPayRate(0.0); } /*Constructor*/ public Employee(String ln, String fn, String bd, String gen, int id, int hrs, double payrt) { //calling super class construtor super(ln, fn, bd, gen); //calling setter methods setEmployeeId(id); setHours(hrs); setPayRate(payrt); } /**Setter method to set payrate value*/ private void setPayRate(double payRate) { this.payRate=payRate; } /**Setter method to set hours value*/ private void setHours(int hours) { this.hours=hours; } /**Setter method to set employeeid value*/ private void setEmployeeId(int employeeId) { this.employeeId=employeeId; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started