Design two sub- classes of Employee...SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An...

60.1K

Verified Solution

Question

Programming

Design two sub- classes of Employee...SalariedEmployee andHourlyEmployee. A salaried employee has an annual salary attribute.An hourly employee has an hourly pay rate attribute, an hoursworked attribute, and an earnings attribute. An hourly employeethat works more than 40 hours gets paid at 1.5 times their hourlypay rate. You will decide how to implement constructors, getters,setters, and any other methods that might be necessary. 1. 2. (20points) Draw a UML diagram for the classes. (80 points) Implementthe classes, and write a test program that creates a salariedemployee and two hourly employees. One of the hourly employeesshould have hours worked set to less than 40 and one should havehours worked set to more than 40. The test program should displayall attributes for the three employees. To keep things simple, theemployee classes don’t need to do any editing.

Here is my code so far:

import java.util.Scanner;

public class Assignment6_lgolden81 {

public static void main(String[] args) {

//Declaring the variables for the main method

String fname, lname, city, state, street;

int employeeNO, zip;

int month, day, year, size;

//This Scanner class object is used to get the input entered bythe user

Scanner input = newScanner(System.in);

System.out.println(\"Please Enter theDesired Number of Employees: \");

size = input.nextInt();

//This is the Array used to hold the employee classinformation

Employee emp[] = new Employee[size];

//This loop is used to get the employee information

for (int i = 0; i < size; i++) {

//This portion of the program gets the input entered by theuser

//prints out the employee number

System.out.println(\"\nEmployee #\" + (i+ 1) + \":\n\");

input.nextLine();

//Prints out the employee's first name

System.out.println(\"\nEnter theEmployee's First Name:\");

fname = input.nextLine();

if (fname.length() < 1) {

System.out.println(\"Invalid Input:Please Enter a Valid First Name!\");

System.exit(0);

}

//Prints out the employee's last name

System.out.println(\"\nEnter theEmployee's Last Name:\");

lname = input.nextLine();

if (lname.length() < 1) {

System.out.println(\"Invalid Input:Please Enter a Valid Last Name!\");

System.exit(0);

}

///Prints out the employee's ID number

System.out.println(\"\nEnter theEmployee's ID Number:\");

employeeNO = input.nextInt();

input.nextLine();

if (employeeNO < 1) {

System.out.println(\"Invalid Input:Please Enter a Valid Employee ID Number!\");

System.exit(0);

}

//Prints out the employee's street address

System.out.println(\"\nEnter the StreetAddress:\");

street = input.nextLine();

if (street.length() < 1) {

System.out.println(\"Invalid Input:Please Enter a Valid Street Name!\");

System.exit(0);

}

//Prints out the name of the City

System.out.println(\"\nEnter theCity:\");

city = input.nextLine();

if (city.length() < 1) {

System.out.println(\"Invalid Input:Please Enter a Valid City Name!\");

System.exit(0);

}

//Prints out the name of the State

System.out.println(\"\nEnter the State(ex. GA):\");

state = input.nextLine();

if (state.length() < 1) {

System.out.println(\"Invalid Input:Please Enter a Valid State Name!\");

System.exit(0);

}

//Prints out the employee's zip code

System.out.println(\"\nEnter the ZipCode:\");

zip = input.nextInt();

if (zip == 0) {

System.out.println(\"Invalid Input:Please Enter a Valid Zip Code!\");

System.exit(0);

}

//While loop used to get the employee's hire date (Month) andmakes sure the input is valid

while (true) {

System.out.println(\"\nEnter Month theEmployee Was Hired:\");

month = input.nextInt();

if (month < 1 || month > 12) {

System.out.println(\">> InvalidInput: Value Must be between 1-12 <<\");

input.close();

continue;

} else

break;

}

//While loop used to get the employee's hire date (Day) andmakes sure the input is valid

while (true) {

System.out.println(\"\nEnter the Daythe Employee Was Hired:\");

day = input.nextInt();

if (day < 1 || day > 31) {

System.out.println(\">> InvalidInput: Value Must be between 1-31 <<\");

continue;

} else

break;

}

//While loop used to get the employee's hire date (Year) andmakes sure the input is valid

while (true) {

System.out.println(\"\nEnter the Yearthe Employee Was Hired:\");

year = input.nextInt();

if (year < 1900 || year > 2020) {

System.out.println(\">> InvalidInput. Value Must be between 1900-2020 <<\");

continue;

} else

break;

}

//Initialized the MyDate method

MyDate md = new MyDate(year, month, day);

//Created an Employee class object and populated the data intoan array

emp[i] = new Employee(fname, lname, md, street, city, state,zip, employeeNO, i);

}

//Displays all of the employee information stored in the Arrayalong with the employee number

System.out.println(\"\nDisplaying theEmployee's Information\");

for (int i = 0; i < size; i++) {

System.out.println(\"\n[Employee #\" +(i + 1) + \"]:\");

System.out.println(emp[i].toString());

}

}

}

// Program Classes

//This class initializes the variables for the year

class MyDate {

private int year;

private int month;

private int day;

//Parameterized constructor

public MyDate(int year, int month, int day) {

super();

this.year = year;

this.month = month;

this.day = day;

}

//Getters and Setters for the year, month, and day

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public int getMonth() {

return month;

}

public void setMonth(int month) {

this.month = month;

}

public int getDay() {

return day;

}

public void setDay(int day) {

this.day = day;

}

@Override

public String toString() {

return month + \"/\" + day + \"/\" + year;

}

}

//Employee class used to initialize the employee information

class Employee {

// Declared employee variables

private int employeeNumber;

private int employeeNO;

private MyDate hireDate;

private String street;

private String city;

private String state;

private String fname;

private String lname;

private int zip;

//Parameterized constructor

public Employee(String fname, String lname, MyDate hireDate,

String street, String city, String state, int zip,intemployeeNO, int employeeNumber) {

super();

this.employeeNumber = employeeNumber;

this.employeeNO = employeeNO;

this.fname = fname;

this.lname = lname;

this.hireDate = hireDate;

this.street = street;

this.city = city;

this.state = state;

this.zip = zip;

}

/* Getters and Setters for the Employee Number, ID, First Name,Last Name,

* Hire Date, Street, City, State, Zip Code

*/

public int getEmployeeNumber() {

return employeeNumber;

}

public void setEmployeeNumber(int employeeNumber) {

this.employeeNumber = employeeNumber;

}

public int getEmployeeNO() {

return employeeNumber;

}

public void setEmployeeNO(int employeeNO) {

this.employeeNO = employeeNO;

}

public String getNamefirst() {

return fname;

}

public void setNamefirst(String fname) {

this.fname = fname;

}

public String getNamelast() {

return lname;

}

public void setNamelast(String lname) {

this.lname = lname;

}

public MyDate getHireDate() {

return hireDate;

}

public void setHireDate(MyDate hireDate) {

this.hireDate = hireDate;

}

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 int getZip() {

return zip;

}

public void setZip(int zip) {

this.zip = zip;

}

//toString method is used to display the contents of an objectinside it

@Override

public String toString() {

return \"\nEmployee ID Number = \" + employeeNO + \"\n\nFirst Name= \" + fname + \"\n\nLast Name = \" +

lname + \"\n\nHire Date = \" + hireDate + \"\n\nStreet = \" + street+ \"\n\nCity = \" + city + \"\n\nState = \"

+ state + \"\n\nZip Code = \" + zip + \"\n\";

}

}

Answer & Explanation Solved by verified expert
4.3 Ratings (646 Votes)
Representative Class subtleties are not given in the inquiry depiction Henceforth the subtleties are accepted for advantageous understanding and utilized in the UML Diagram Kindly dont hesitate to change according to the planned    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students