

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
An assignment for creating a java program based on the given uml diagram. The assignment involves creating five related classes, making all fields private, making all methods public, initializing fields via constructor calls, and implementing abstract methods. The classes are employee (abstract), salaried, waged, and sales. The objective is to understand inheritance, 'is-a' relations, abstract methods, and polymorphism.
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Make all fields (i.e., instance variables or attributes) private
Make all methods public
Make all classes public (each class in its own file)
Initialize all fields / instance variables via constructor calls
Each toString method should return a string representation of the implicit object; this usually includes all fields contained in the objectand in any super classes or classes joined by “has-a” relationships. The format of the returned string is not important. The toStringmethod should not print or display the value of any fields - just concatenate and return them
class Employee (make this class abstract)a.^
calcPay: make this method abstract
class Salarieda.^
calcPay returns
salary / 24
b.
Format is not important
class Wageda.^
calcPay returns
hours * wage
b.
Format is not important
class Salesa.^
calcPay returns the salary plus a commission:
salary / 24 + commission * totSales
. However, salary is a private
variable, how will you solve this problem? b.
Format is not important
together and note that Lab9.java is not needed. (Note that I will be using the posted version of Lab9.java, which implies that you shouldnot make changes to it.) Note that this “pushes” data into the objects with constructor calls and to “pulls” data from the objects using toString, and calcPay. Theobjective to better understand inheritance, “is-a” relations, abstract methods and classes, and polymorphism.
-name : String+ Employee(name : String, street : String, city : String)+ toString() : String + calcPay() : double
Employee
-street : String-city : String+Address(street : String, city : String)+toString() : String
Address
-salary : double+Salaried(name : String, street : String, city : String, salary : double)+toString() : String+calcPay() : double
Salaried
-hours : double-wage : double+Waged(name : String, street : String, c ity : String, hours : double, wage : double)+toString() : String+calcPay() : double
Waged
-commission : double-totSales : double+Sales(name : String, street : String, city : String, salary : double, commission : double, totSales : double)+toString() : String+calcPay() : double
Sales