Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to complete the Employee class using the source code given below.To include all Constructors, Mutators and Accessors (including toString()). NOTE: InputValid.java (below) must be

How to complete the Employee class using the source code given below.To include all Constructors, Mutators and Accessors (including toString()).

NOTE: InputValid.java (below) must be saved to a file named InputValid.java.

Students are to create a class file based on:

public class Employee extends Person { // Attributes: private int employeeId; private int hours; private double payRate; private double wages;

// Overloaded Constructors: public Employee() { super(); setEmployeeId(0); setHours(0); setPayRate(0.0); } public Employee(String ln, String fn, String bd, String gen, int id, int hrs, double payrt) { super(ln, fn, bd, gen); setEmployeeId(id); setHours(hrs); setPayRate(payrt); }

1.

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; } }

2,

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 payrollList; public static void main(String[] args) { payrollList = new ArrayList(); int count = 0; do { String firstName = InputValid.getString("What is the employee's first name?", "Enter First Name", "Please enter the first name."); String lastName = InputValid.getString("What is the employee's last name?", "Enter Last Name", "Please enter the last name."); String birthday = InputValid.getString("What is the employee's birthday? (e.g., 11/22/1999)", "Enter Birthday", "Please enter the birthday."); String gender = InputValid.getString("What is the employee's gender?", "Enter Gender", "Please enter the gender."); int empID = InputValid.getInt("What is the employee's ID number?", "Enter Employee ID Number", "Please enter the ID number."); int hours = InputValid.getInt("Please enter the employee's hours worked:", "Enter Hours Worked", "Please enter the hours worked."); double rate = InputValid.getDouble("Please enter the employee's pay rate:", "Enter Pay Rate", "Please enter the pay rate."); payrollList.add(new Employee(lastName, firstName, birthday, gender, empID, hours, rate)); count++; } while (JOptionPane.showConfirmDialog(null, "Do you want to enter another employee?","Another?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION); for (int i=0; i 

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; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

What is Indian Polity and Governance ?

Answered: 1 week ago