Question: This assignment will use the Employee, Name, Address, and Date classes which you developed for Module Assignment 6. Add the following changes to your Module
This assignment will use the Employee, Name, Address, and Date classes which you developed for Module Assignment 6. Add the following changes to your Module 6 Assignment: change Employee class, Name class, Address class, and Date class instance variables to private; move data validation to target class. Then, Design two sub-classes of Employee, SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An hourly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate for all hours over 40. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary. Draw a UML diagram for the classes used in your implementation. Implement the classes, and write a test program that creates (internally, do not prompt the user) a salaried employee and two hourly employees. One of the hourly employees should have hours worked set to less than or equal to 40 and one should have hours worked set to more than 40. Create a 3-element Employee array and place the three Employees in this array. The test program should display all attributes for the three employees eitracted from the array.
Previous Assignment:
EmployeeModel.java
import java.util.Scanner;
public class EmployeeModel
{
public static void main(String[] args)
{
Scanner input = new Scanner ( System.in );
System.out.println ( "How many new employees would you like to "
+ "enter?" );
System.out.println();
int newEntrySize = input.nextInt();
Employee [] employees = new Employee[newEntrySize];
for ( int i = 0; i < newEntrySize; i++ )
{
System.out.println ( "Please enter employee number: " );
System.out.println();
input.nextLine();
String employeeNumber = input.nextLine().toString();
if ( employeeNumber.isEmpty() )
{
System.out.println ( "Invalid entry. Please enter an "
+ "employee number: " );
System.out.println();
input.nextLine();
}
System.out.println ( "Please enter employee's first name: " );
System.out.println();
String firstName = input.nextLine();
if ( firstName.isEmpty() )
{
System.out.println ( "Invalid entry. Please enter "
+ "employee's first name: " );
System.out.println();
input.nextLine();
}
System.out.println ( "Please enter employee's last name: " );
System.out.println();
String lastName = input.nextLine();
if ( lastName.isEmpty() )
{
System.out.println ( "Invalid entry. Please enter "
+ "employee's last name: " );
System.out.println();
input.nextLine();
}
Name name = new Name ( firstName,lastName );
System.out.println ( "Please enter employee street address: " );
System.out.println();
String street = input.nextLine();
if ( street.isEmpty() )
{
System.out.println ( "Invalid entry. Please enter "
+ "employee street address: " );
System.out.println();
input.nextLine();
}
System.out.println ( "Please enter employee city: " );
System.out.println();
String city = input.nextLine();
if ( city.isEmpty() )
{
System.out.println ( "Invalid entry. Please enter "
+ "employee city" );
System.out.println();
input.nextLine();
}
System.out.println ( "Please enter employee state using "
+ "two letter abbreviation (e.g., type CA for "
+ "California): " );
System.out.println();
String state = input.nextLine().toUpperCase();
if ( state.isEmpty() )
{
System.out.println ( "Invalid entry. Please enter "
+ "employee state: " );
System.out.println();
input.nextLine();
}
System.out.println ( "Please enter employee zipcode: " );
System.out.println();
String zipcode = input.nextLine();
if ( zipcode.isEmpty() )
{
System.out.println ( "Invalid entry. Please enter "
+ "employee zipcode: " );
System.out.println();
input.nextLine();
}
Address address = new Address ( street, city, state, zipcode );
System.out.println ( "Please enter employee hiring year as a "
+ "4-digit number (e.g., 2018): " );
System.out.println();
int hireYear = input.nextInt();
if ( hireYear < 1900 || hireYear > 2020 )
{
System.out.println ( "Invalid year. Please enter a year "
+ "between 1900 and 2020" );
System.out.println();
input.nextInt();
}
System.out.println ( "Please enter employee hiring month as a "
+ "number between 1 and 12 (e.g., enter 1 for "
+ "January): " );
System.out.println();
int hireMonth = input.nextInt();
if ( hireMonth < 1 || hireMonth > 12 )
{
System.out.println ( "Invalid month. Please enter a "
+ "month between 1 and 12." );
System.out.println();
input.nextInt();
}
System.out.println ( "Please enter employee hiring day: " );
System.out.println();
int hireDay = input.nextInt();
if ( hireDay < 1 || hireDay > 31)
{
System.out.println ( "Invalid day. Please enter a day "
+ "between 1 and 31" );
System.out.println();
input.nextInt();
}
Date date = new Date ( hireDay, hireMonth, hireYear );
Employee employee = new Employee ( employeeNumber, name,
address, date );
employees[i] = employee;
}
for ( Employee e: employees )
{
System.out.println ( e.toString() );
}
input.close();
}
}
Name.java
public class Name
{
String firstName;
String lastName;
public Name ( String firstName, String lastName )
{
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName()
{
return firstName;
}
public void setFirstName ( String firstName )
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName ( String lastName )
{
this.lastName = lastName;
}
public String toString()
{
return firstName + " " + lastName;
}
}
Address.java
public class Address
{
//Initialization of instance variables
String street;
String city;
String state;
String zipcode;
public Address ( String street, String city, String state,
String zipcode )
{
this.street = street;
this.city = city;
this.state = state;
this.zipcode = zipcode;
}
public String getStreet()
{
return street;
}
public void setStreet ( String street )
{
this.street = street;
}
public String getCity()
{
return city;
}
public void setCity ( String city )
{
this.city = city;
}
public String getState()
{
return state;
}
public void setState ( String state )
{
this.state = state;
}
public String getZipcode()
{
return zipcode;
}
public void setZipcode ( String zipcode )
{
this.zipcode = zipcode;
}
public String toString()
{
return street + ", " + city + ", " + state + ", " + zipcode;
}
}
Date.java
public class Date
{
int hireDay;
int hireMonth;
int hireYear;
public Date ( int hireDay, int hireMonth, int hireYear )
{
setDay ( hireDay );
setMonth ( hireMonth );
setYear ( hireYear );
}
public int getDay()
{
return hireDay;
}
public void setDay ( int hireDay )
{
this.hireDay = hireDay;
}
public int getMonth()
{
return hireMonth;
}
public void setMonth ( int hireMonth )
{
this.hireMonth = hireMonth;
}
public int getYear()
{
return hireYear;
}
public void setYear ( int hireYear )
{
this.hireYear = hireYear;
}
public String toString()
{
return hireDay + "-" + hireMonth + "-" + hireYear;
}
}
Employee.java
public class Employee
{
String employeeNumber;
Name name;
Address address;
Date date;
public Employee ( String employeeNumber, Name name, Address address,
Date date )
{
this.employeeNumber = employeeNumber;
this.name = name;
this.address = address;
this.date = date;
}
public String getEmployeeNumber()
{
return employeeNumber;
}
public void setEmployeeNumber ( String employeeNumber )
{
this.employeeNumber = employeeNumber;
}
public Name getName()
{
return name;
}
public void setName ( Name name )
{
this.name = name;
}
public Address getAddress()
{
return address;
}
public void setAddress ( Address address )
{
this.address = address;
}
public Date getDate()
{
return date;
}
public void setdate ( Date date )
{
this.date = date;
}
public String toString()
{
return "Employee {" + "Employee Number: " + employeeNumber +
", Name: " + name + ", Address: " + address +
", Hire Date: " + date + "}";
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
