Question

In: Computer Science

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

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. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary. 1. 2. (20 points) Draw a UML diagram for the classes. (80 points) Implement the classes, and write a test program that creates a salaried employee and two hourly employees. One of the hourly employees should have hours worked set to less than 40 and one should have hours worked set to more than 40. The test program should display all attributes for the three employees. To keep things simple, the employee 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 by the user

Scanner input = new Scanner(System.in);

System.out.println("Please Enter the Desired Number of Employees: ");

size = input.nextInt();

//This is the Array used to hold the employee class information

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 the user

//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 the Employee'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 the Employee'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 the Employee'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 Street Address:");

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 the City:");

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 Zip Code:");

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) and makes sure the input is valid

while (true) {

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

month = input.nextInt();

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

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

input.close();

continue;

} else

break;

}

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

while (true) {

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

day = input.nextInt();

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

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

continue;

} else

break;

}

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

while (true) {

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

year = input.nextInt();

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

System.out.println(">> Invalid Input. 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 into an array

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

}

//Displays all of the employee information stored in the Array along with the employee number

System.out.println("\nDisplaying the Employee'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,int employeeNO, 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 object inside 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";

}

}

Solutions

Expert Solution

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 don't hesitate to change according to the planned needs.

UML Diagram:

Employee Class:

  1. Employee is the parent class as perceived from the inquiry.
  2. The factors and strategies are accepted as subtleties were not given being referred to.

HourlyEmployee is the sub class.:

  1. Hourly_Payrate is the variable to store hourly payrate.
  2. Hours_Worked is the variable to store number of hours worked.
  3. Profit is the variable to store the gross income.
  4. SetHours() is the setter strategy to set Hourly_Payrate and Hours_Worked.
  5. GetEarnings() is the getter technique to get gross profit. This technique computes the profit dependent on the quantity of hours worked. In the event that >40 hours, at that point 1.5 occasions the hourly payrate.

SalariedEmployee Class:

  1. AnnualSalary is the variable to store the compensation of the representative.
  2. Income is the variable to store the gross profit.
  3. SetAnnualSalary() is the setter technique to set yearly compensation for the worker.
  4. GetEarnings() is the getter technique to get gross income.

Related Solutions

Design two sub- classes of Employee...SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute....
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. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary. 1. (20 points) Draw a UML diagram for the classes. 2. (80...
Aimee is a salaried nonexempt employee who earns an annual salary of $54,000 for a 35-hour...
Aimee is a salaried nonexempt employee who earns an annual salary of $54,000 for a 35-hour workweek, paid biweekly. The employer pays overtime for any hours worked in excess of 35 per week. During a pay period, she worked 73.5 hours. She has requested that she take compensatory time in lieu of paid overtime. How much compensatory time should she receive, assuming that her firm approves the compensatory time? 3.5 hours 2.75 hours 5.25 hours 10.25 hours
Joey receives two job offers: Job A has a starting annual salary of $80,000 and an...
Joey receives two job offers: Job A has a starting annual salary of $80,000 and an expected annual salary growth of 7%. Job B has a starting annual salary of $100,000 and an expected salary growth of 5%. Joey is 30 years old and plans to retire when he turns 65. Ignore bonuses, pensions, other compensations and taxes; all cash flows will be made at the end of each year. Joey discounts future cash flows at an effective annual rate...
Create a class called employee which has the following instance variables: Employee ID number Salary Years...
Create a class called employee which has the following instance variables: Employee ID number Salary Years at the company Your class should have the following methods: New employee which reads in an employee’s ID number, salary and years of service Anniversary which will up the years of service by 1 You got a raise which will read in how much the raise was (a percent) and then calculate the new salary You get a bonus which gives a yearly bonus...
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments....
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to do the following: 1....
The annual salary of teachers in a certain state has a mean of μ = $...
The annual salary of teachers in a certain state has a mean of μ = $ 54,000 and standard deviation of σ = $ 5,000 . What is the probability that the mean annual salary of a random sample of 5 teachers from this state is more than $60,000?
A) Maria is single with no dependents and has an annual salary of $125,000. She is...
A) Maria is single with no dependents and has an annual salary of $125,000. She is considering the purchase of a $400,000 house. While she was house-hunting, the 2017 tax act passed, changing the deductions and tax brackets and limiting the deduction for state and local taxes (SALT) to $10,000. Prior to 2018, the standard deduction for a single person was $6,350 and a person exemption of $4,050. A portion of the taxable income-brackets was: Over But Not Over Percentage...
Write code in java using the LinkedList connecting two different classes. For example, Employee and EmployeeList...
Write code in java using the LinkedList connecting two different classes. For example, Employee and EmployeeList are two different classes that are used to create the assignment.
Case Study: A Tale of Two Classes Ebony Ellis has two communication classes back-to-back in the...
Case Study: A Tale of Two Classes Ebony Ellis has two communication classes back-to-back in the same room, but they couldn’t be more different. The first, a class on interpersonal communication, is taught by Steve Gardner, an older professor who has taught at the university for 20 years. The first day of class he verbally explained the rules for class conduct, which were also distributed in a printed handout—cell phones off, no texting, and, unless a student needs to use...
Two university graduates, Bill and Steve, worked for an advertising agency at an annual salary of...
Two university graduates, Bill and Steve, worked for an advertising agency at an annual salary of $40,000 each for 3 years after they graduated. Then, they decided to quit their jobs and start a partnership that designs and builds Web sites. They rented an office for $12,000 a year and bought capital for $30,000. To pay for the equipment, Bill and Steve borrowed money from a bank at an annual interest rate of 6 percent. During their first year of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT