1 Designing a Class Hierarchy Using an Abstract Base Class In this assignment, y
ID: 3793059 • Letter: 1
Question
1 Designing a Class Hierarchy Using an Abstract Base Class
In this assignment, you will design and implement a payroll system using an abstract base class
(ABC). The goal is to emphasize design using ABC's and to practice how to properly implement
it in a programming language of your choice.
1.1 The Speci cation
The program you are asked to design and write processes payroll data for a collection of employees.
Employees are either salaried or hourly. At the end of the month, salaried employees receive a xed
pay. Hourly employees, however, receive a pay that is determined by their hourly rate times the
actual hours worked. The payroll system will print out the last name of each employee along with
the pay due to the employee, separated by a space. This simulates an actual payroll system, which
uses this information to actually print and cut the checks.
1.2 The Class Hierarchy
Before writing any code, your task is to design the class hierarchy. Think of a good way to organize
the data needed for each type of employee before refactoring commonalities into an abstract base
class. Questions you should ask at this stage of the design include:
What pieces of data do I need to represent a salaried employee?
What pieces of data do I need to represent an hourly employee?
What pieces of data do salaried and hourly employees have in common?
What data do I need to determine an employee's pay and how is computing pay di erent for
varying kinds of employees?
Draw the class hierarchy either by hand or with an appropriate tool. Feel free to use UML Notation,
but for something as simple as this, the Business Object Notation is probably more appropriate.
You can use any format you want (even your own) as long as you clearly indicate inheritance
relationships and deferred functions (a.k.a. virtual functions).
1
2 The Implementation
After you have designed the class hierarchy, you need to express it in a programming language.
As a general rule of thumb, this will result in a set of several classes plus a driver program which,
depending on the language, will be stored in one or more les:
One implementation per class, containing the class de nition
A driver program, usually containing the main() (or equivalent) function to demonstrate the
hierarchy's functionality.
More complex projects use separate compilation and a build system to compile and build our nal
executable, but for the time being, it is totally ne to compile everything at once on the command
line or just creating a project in the integrated development environment of your choice. If you
need help on the speci cs because you lack experience or con dence in creating executables, please
don't hesitate to contact the class instructor.
When implementing your design, make sure to pick appropriate data and container types. Please
ask yourself the following questions before settling on a type:
Can pay, hours, and the hourly rate ever be negative or zero?
Is pay more appropriately expressed using an integer or
oating point type?
Can the employee name ever be empty?
Can the name ever contain characters not usually found in American English?
Is it more important to eciently read or write to the employees container?
Is it more important to insert or delete elements of the employees container?
The answers to these questions determine the actual design of your software system and are not
absolute but must be chosen in consideration of technical, legal, regulatory, economic, ethical, and
any other professional requirements applicable to the domain the software system is intended to
operate under. As such, there is not a single answer and your design and implementation may di er
signi cantly from that the instructor had in mind. You are expected (within reasonable limits, this
being a class on software engineering) to justify and defend your design choices to the instructor or
class as a whole and to modify your design or implementation accordingly based on that feedback.
3 The Driver Program
In order to demonstrate the functionality of your design, you should write a driver program. This
will be the usual main() function. Upon execution, it should
Create an appropriate polymorphic container to hold the employee information.
Create at least two of each kind of employee, in an arbitrary order and insert it into the
container. Sample input:
Name Type Salary Hours Rate
Parsons Salaried 90000 n/a n/a
Galecki Salaried 80000 n/a n/a
Laurel Hourly n/a 20 160
Hardy Hourly n/a 19 150
Iterate over the elements of the container, printing both the employees last name and the pay,
each on a separate line. Sample output:
Parsons 90000
Galecki 80000
Laurel 3200
Hardy 2850
Make sure you use polymorphism and dynamic binding to avoid switching on type while
printing the paychecks. This means that the driver program should not contain any if or
switch (or similar) statements.
In languages without garbage collection, after processing and before terminating, you need to
appropriately delete the objects if they have previously been allocated on the heap.
Here's the pseudocode for the driver program:
objects := create Container
object := create SalariedObject(Parsons, 90000)
insert object into objects
object := create SalariedObject(Galecki, 80000)
insert object into objects
object := create HourlyObject(Laurel, 20, 160)
insert object into objects
object := create HourlyObject(Hardy, 19, 150)
insert object into objects
for object in objects:
object.printPaycheck()
4 Work Summary
Design a class hierarchy that best ts the speci cation. (Hint: 3 classes should suce and
one should be an abstract base class, containing at least one deferred (a.k.a. pure virtual)
function).
Draw the class hierarchy.
Pick appropriate data types to represent the di erent employee attributes.
Select useful names for classes, data members, and member functions.
Write a driver program to demonstrate use of the class hierarchy.
In the driver, use a polymorphic container of your choice to hold the employee information.
Iterate over the polymorphic container and print, on a separate line, each employee's last
name and computed pay.
Please try to adhere to a consistent coding style for the language of your choice in terms of
naming classes, data members, member functions, indentation, placement of parentheses and
braces, etc.
Submit the source code (no object code or executable, please) via Git. Put the SHA1 hash
of the commit into the assignemt's submission text box.
Submit the output of a sample run to Blackboard. Use copy and paste to put the output into
the assignment's submission text box.
Explanation / Answer
1.The program to design and write processes payroll data for a collection of employees:
public class Chegg1 {
public void check( int id ,String name,int workingdays){
if (id==561&&name.equals("sarathi")&&workingdays>25) {
System.out.println("pay the money to the employee ");
}
else {
System.out.println(" sorry employee details not matched");
}
}
public static void main(String[] args) {
Chegg1 ch=new Chegg1();
ch.check(561,"sarathi", 26);
ch.check(100, "raju", 18);
}
}
Output:pay the money to the employee
sorry employee details not matched
2.Implement Employee payroll system:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.