CS 161 Recitation 10b

Overview

This recitation will cover inheritance, polymorphism, and abstract classes.

Assignment

This lab will be a variant on the previous one, and again will concern a software development company, and is aimed at modeling employees and software projects. Assume the company has the following types of employees: programmers, and testers (we will ignore managers since they don't contribute to the completion of projects). This will be represented by the following Java class hierarchy:
       Employee
       /      \
Programmer    Tester
Employee is an abstract class that represents the notion of an employee. It has an abstract method called work(), that the classes Programmer and Tester will provide an implementation for. A Programmer writes code, and the Tester is focused on testing it. You will need the following starter files:

The Employee class

The Employee class contains functionality common to types of employees in the company. For example, all employees have a name and ID number. This class is missing a constructor, and getter/setter methods.

Programmer

The Programmer class is a sub-class of Employee. A given programmer can write a certain number of lines of code per day, captured by an instance variable linesOfCodePerDay. A programmer's work method returns the number of lines of code he/she wrote on a given day, which is a random number between 50% and 150% of linesOfCodePerDay (some days are not as good as others, and some tasks are harder/easier than others).

Tester

The Tester class is a sub-class of Employee. A given Tester can test a given number of lines of code per day, captured by an instance variable linesOfCodeTestedPerDay. A tester's work method returns the number of lines of code he/she tested that day, which is a random number between 75% and 125% of linesOfCodeTestedPerDay.

Project

The class Project models a software development project. It should have the following attributes: The project is complete once all the code is written and tested. The class should have the following methods: The main method of this class should create a new instance of Project, add a few programmers and testers, run the doProject() method, and report how long it took and whether it was completed on time.

Tasks

Question: where have we used the Java concept of polymorphism?