Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CISC231 Foundations of Computing II Assignment 5 (100 pts): Create a class named Yourlastname_Yourfirstname_hw5. Add the following default classes below this Yourlastname_Yourfirstname_hw5.class: Class Employee: Create

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
CISC231 Foundations of Computing II Assignment 5 (100 pts): Create a class named Yourlastname_Yourfirstname_hw5. Add the following default classes below this Yourlastname_Yourfirstname_hw5.class: Class Employee: Create a default class called Employee. An employee should include seven pieces of information as instance variables: 1. name: the name of the employee 2. id: an automatically generated string based on the year this employee was hired (4 digits) + this employee was the _th hire of the year (4 digits). For example, the 15th employee hired in 2020 should be "20200015". 3. hireYear: the year that the employee was hired. 4. username: automatically generated string based on the following rules: a. Get the first character of the employee's first name Get the employee's entire last name c. Join them together, and make each character lowercase d. Add a number at the end based on how many existing usernames that are the same to make sure that all usernames are unique For example, if the employee's name is David Smith and "dsmith", "dsmith2", and "dsmith3" already exist in the employees csv file, then David's username should be "dsmith4." . rank: an integer value in the range of 1 to 10 to show this employee's level within the company. The higher the number is, the higher rank this employee holds. 6. yearlyPayment: the employee's income for this year. 7. department: an object of the class Department. The department the employee works in. Also, create a static variable, called numEmployee, to keep track of the number of employee objects that have been created. Employee records should be stored in a .csv file called employees.csv in the following format: Each row represents an employee's information with each column representing different attribute values of the employees, i.e, name, id, username, rank, yearlyPayment, and department's departmentName in this order. An example is given below: Page | 1AutoSave ( Off) H employees.csv v File Home Insert Draw Page Layout Formulas Data Review View Automate Help Calibri 11 ~ A" A " General Paste LE ~ Conditional Formatting Undo Clipboard Font Alignment Number E10 v :XV name id username rank yearlyPayment department's departmentName A I B IC G H 1 Alex Smith 20200001 asmith 100000 HR 2 Adam Smith 20210001 asmith1 80000 IT Allison Smith 20210002 asmith2 75000 IT Tasks: 1. Add a constructor. The attributes, name, hire Year, yearlyPayment, and rank, must be specified. The attributes, id and username, are generated automatically. The initial value of the attribute, department, should be null . Add a get method for each attribute. 3. Add a set method for the attribute, name. 4 . Add a promote() method to promote an employee's rank by one. This employee's yearlyPayment should also be increased by 10,000 dollars for each promotion. 5. Add a saveRecord() method to save this employee's data to the employees.csv file when this employee object is created. 6. Employee objects should be comparable based on their ranks. Implement the Comparable interface. 7. You may add some private utility methods to facilitate your design. Class HourlyPaidEmployee: Create a class called HourlyPaidEmployee, which is a special type of employee. HourlyPaidEmployees do not get a flat salary. Instead, their annual salaries are calculated based on the number of hours they work. Therefore, this special class should have two additional attributes: 1. hourlyPayRate: hourly pay rate of this employee 2. hoursWorked: how many hours worked so far. Its initial value should be zero. Tasks: 1. Add a constructor. 2. Add a get method for hourlyPayRate and hoursWorked. 3. Add a method called enterHours(int hours) that can add the given hours to the existing number of hours worked so far. The yearlyPayment should be adjusted accordingly. 4. Add a set method for hourlyPayRate that can update this employee's hourlyPayRate Page | 2Class Executive: Create a class called Executive, which is another special type of employee. Executives have different promotions, which give them additional benefits: Tasks: 1. Add a constructor. 2. The promote() method should also increase an executive's rank by one. However, unlike a regular employee, an executive's yearlyPayment should be increased by 20,000 dollars for each promotion. Class Department: Create a class called Department. A department should have the following four attributes: 1. departmentName: the name of the department . 2. capacity: a constant value to indicate the maximum number of employees that this department can hire. 3. numMember: an integer value to indicate the number of employees currently in this department. 4. roster: an array that holds all of the employee objects who work in this department. Tasks: 1. Add a constructor. 2. Add a get method for each attribute. 3. Add a method called add(Employee e) that can add an employee (can be a regular employee, an hourlyPaidEmployee, or an executive) to the department. Assign this department to the employee object's department attribute. Throw the IndexOutOfBoundsExecption if the number of employees has exceeded maximum capacity for the department. . Add a method called transfer(Department other, Employee e) that can transfer the given employee from the department to the other specified department. If the other department has reached its capacity limit, then throw the IllegalStateException. If the given employee is not in the department, then throw the NoSuchElementException. 5. Implement Iterable and Iterator interfaces. After you implement those two interfaces, you should be able to loop through each employee object in this department. Again, you may add additional private utility methods to facilitate your design. In Yourlastname_Yourfirstname_hw5 class, create two departments as shown below. Call each method to test its functionality. Department department1 = new Department("IT", 20); Department department2 = new Department("HR", 8); Create four employee objects: Employee e1 = new Executive("Alex Smith",2020, 5, 100000); // username = asmith, id = 20200001 Employee e2 = new Employee("Adam Smith", 2021, 4, 80000); // username = asmith2, id = 20210001 Employee e3 = new Employee("Allison Smith",2021,3, 75000); // username = asmith3 id = 20210002 Page | 3Employee e4 = new HourlyPaidEmployee("Andrew Smith", 2021, 3, 20); // username = asmith4, id = 20210003, hourlyPayRate = 20 Add employee objects, el to department2. Add employee objects, e2, e3 and e4 to department1. Then transfer e4 from department1 to department2. Submit your Yourlastname_Yourfirstname_hw5.java file on blackboard. Page | 4

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions