CS 207 Programming II

CS 207 – Homework 2This homework is due on Monday February 20th at 11:59p.
To submit, follow the syllabus guidelines.
PART 1 (60 pts)
Implement your code:
In this question, you are required to complete four classes: Employee, StudentWorker,
Faculty, and FileOperator. The Employee class is an abstract super class that represents
plain employees and the StudentWorker and Faculty classes are concrete subclasses that
inherit from the Employee class. The FileOperator class saves the content of an Employee
array into a physical file on the disk.
For the Employee class, implement the following:
A private String instance variable m_name.
A private String instance variable m_department.
A constructor that takes two parameters (in the order of name, department) and sets the
instance variables.
A getter method for m_name and a getter method for m_department.
An abstract String method named getPaycheck that does not take any parameter.
For the StudentWorker class, implement the following:
A private int instance variable m_hours.
A private int instance variable m_hourlyWage.
A constructor that takes four parameters (in the order of name, department, hours,
hourly wage). It should use the parameters for hours and hourly wage to set the m_hours
and m_hourlyWage instance variables and then explicitly call the parent class
constructor using the super keyword and pass in the two other parameters.
A getPaycheck method that implements the same method in the Employee class. It
calculates the paycheck amount (m_hours × m_hourlyWage) and returns the student
worker’s paycheck as a string in the following format. Note that the three fields are
separated by a hyphen, represented by the minus character. Do NOT add spaces
before or after each hyphen. There are no commas in the number. See example:
Optimus Prime-Computer Science-$1200
For the Faculty class, implement the following:
A private int instance variable m_salary.
A constructor that takes three parameters (in the order of name, department, salary). It
should use the parameter for salary to set the m_salary instance variable and then
explicitly call the parent class constructor using the super keyword and pass in the two
other parameters.
A getPaycheck method that implements the same method in the Employee class. It
returns the faculty member’s paycheck as a string in the following format (the amount of
money is equal to m_salary) See example:
Pooh-Mathematics-$50000
For the FileOperator class, the class skeleton is already provided to you. The only method
you should modify and implement is writeFile. This method takes an array of employees,
and each element can be a Faculty object or a StudentWorker object. Your task is to identify
the type of the object using the instanceof keyword and write a line representing this object to
the file using reference m_file. If the current object is a Faculty, then add a prefix “F-” to the
string returned by getPaycheck and write this line to the file. Otherwise, if the current object is a
StudentWorker, the prefix should be “S-”. For example:
S-Optimus Prime-Computer Science-$1200
F-Pooh-Mathematics-$50000
Test your code:
You are provided with a test driver implemented in “TestEmployees.java” (do not make any
changes to this file!) so there is no need to write your own testing code.
Once you have completed the above classes, you can run the test. You should create a plain text
file named “output.txt”, copy and paste the output (if your code crashes or does not compile,
copy and paste the error messages) to this file and save it.
Grading Rubric:
Code does not compile: -10
Code compiles but crashes when executed: -5
Changes were made to things other than the Employee, StudentWorker, Faculty
classes and the writeFile method in the FileOperator class: -5
Has output file: 5
Employee was declared as an abstract super class: 5
Employee class has correct instance variables: 2
Employee’s constructor was correctly implemented: 5
Employee’s two getters were correctly implemented: 6
Employee’s getPaycheck method is abstract and has no body: 3
StudentWorker inherits from Employee: 5
StudentWorker class has correct instance variables: 2
StudentWorker’s constructor was correctly implemented: 5
StudentWorker’s getPaycheck method was correctly implemented: 5
Faculty inherits from Employee: 5
Faculty class has the correct instance variable: 2
Faculty’s constructor was correctly implemented: 5
Faculty’s getPaycheck method was correctly implemented: 5
writeFile method correctly implemented: 10
Sample Output:
Test 1: Create and add Faculty(“Bumble Bee”, “Social Science”, 80000) ==>
[Passed]
Test 2: Create and add StudentWorker(“Harry Potter”, “Computer Science”, 20,
15) ==> [Passed]

Test 7: getPaycheck() for object StudentWorker ==> [Passed]
Expected:
Harry Potter-Computer Science-$300
Yours:
Harry Potter-Computer Science-$300
Test 8: getPaycheck() for object StudentWorker ==> [Passed]
Expected:
Pooh-Accounting-$260
Yours:
Pooh-Accounting-$260

Test 11: writeFile() ==> [Passed]
Expected:
F-Bumble Bee-Social Science-$80000
S-Harry Potter-Computer Science-$300
S-Pooh-Accounting-$260
F-Kungfu Panda-Finance-$95000
S-Luigi-Chemistry-$255
Yours:
F-Bumble Bee-Social Science-$80000
S-Harry Potter-Computer Science-$300
S-Pooh-Accounting-$260
F-Kungfu Panda-Finance-$95000
S-Luigi-Chemistry-$255
Total test cases: 11
Correct: 11
Wrong: 0

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER