
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Assignment #3 for the cop3330 course, due in fall 2001. Students are required to create boss and hourlyworker classes by extending the employee base class, write a testemployee class with a main() method, and implement specific methods and constructors. The objective is to learn about writing extended classes, abstract classes, character-based io, and string manipulation methods.
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

COP3330.01, Fall 2001 Assigned: 9/27/ S. Lang Assignment #3 Due: 10/11 in class (Note: minor corrections in boldface font added 10/03) The objectives of this assignment is to learn about how to write extended classes, the idea of abstract class and method, character-based IO, and some string manipulation methods. You will be given an abstract class Employee (in file Employee.java) as the base class. In this assignment, you are to create a Boss class and an HourlyWorker class by extending the base class. Also, you are to write a TestEmployee class with a main() method to test your java programs. The following specifies the detailed requirements: (1) The Boss class should have one private instance variable (field) weeklySalary of type double, and contain one constructor: Boss(String first, String last, double salary) which creates a Boss object and initializes the fields firstName, lastName, and weeklySalary based on the corresponding parameters; contain a method: public String toString() that returns a string that says “Boss: “ followed by the person’s first name and last name, all on the same line; and contain an implementation of the earnings() method that returns the value of the instance variable weeklySalary. (2) The HourlyWorker class should have two instance variables wage and hours, both of type double, and contain a constructor: HourlyWorker(String first, String last, double wagePerHour, double hoursWorked) that creates a HourlyWorker object initializing the corresponding instance variables; contain the following methods public void setWage(double wagePerHour) and public void setHours(double hoursWorked) for resetting the fields wage and hours, respectively; contain a method: public String toString() that returns a string that says “HourlyWorker: “ followed by the person’s first name and last name, all on the same line; and contain an implementation of the earnings() method that returns the value of wage*hours (i.e., the weekly pay). (3) The TestEmployee class that contains a main() method to perform the following tasks: (a) Prompt the user for the number of employee objects, then create an array of that size; (b) Read input of employee records from the keyboard, where each input starts with a string “Boss” or “HourlyWorker”, followed by the firstName and lastName of the Employee (both of String type), followed by either a single number (for Boss object) or two numbers (for HourlyWorker object), all data for the same employee on the same line. The main() needs to “tokenize” the line and create the corresponding object, then store each object at the next index of the array. (c) The input continues until either the input ends or when the array size is reached. At that point, use a loop to output all employee objects saved in the array using the toString() method, with one object’s string per line. The instructor will provide the Employee.java file for the Employee base class, and several input files that contain sample employee records for testing your program. Prepare your homework the same way as in the previous assignment: source files on a disk, a hardcopy of the source and a hardcopy of each of the output results , put all information in a brown envelope with your name, social security number, and which java environment you use, written on the envelope.