Lab 9: Java Program for Class Relationships and Multi-Class Programs, Lab Reports of Computer Science

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

Pre 2010

Uploaded on 07/22/2009

koofers-user-5rv
koofers-user-5rv 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab #9
Class Relationships and Multi-Class Programs
Assignment
Write a Java program consisting of the five related classes presented in the UML diagram on the next page. Please note that what looks like a
‘0’ following toString and calcPay methods in the UML class diagrams are empty parentheses.
1. Make all fields (i.e., instance variables or attributes) private
2. Make all methods public
3. Make all classes public (each class in its own file)
4. Initialize all fields / instance variables via constructor calls
5. Each toString method should return a string representation of the implicit object; this usually includes all fields contained in the object
and in any super classes or classes joined by “has-a” relationships. The format of the returned string is not important. The toString
method should not print or display the value of any fields - just concatenate and return them
6. class Employee (make this class abstract)
a. calcPay: make this method abstract
7. class Salaried
a. calcPay returns salary / 24
b. Format is not important
8. class Waged
a. calcPay returns hours * wage
b. Format is not important
9. class Sales
a. 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
10. Complete the assignment with Lab9.java, which contains main and which is posted with this assignment
11. Upload Employee.java, Salaried.java, Waged.java, Sales.java and Address.java to WSU Online for grading – please do not zip the files
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 should
not 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. The
objective to better understand inheritance, “is-a” relations, abstract methods and classes, and polymorphism.
pf2

Partial preview of the text

Download Lab 9: Java Program for Class Relationships and Multi-Class Programs and more Lab Reports Computer Science in PDF only on Docsity!

Lab

Class Relationships and Multi-Class Programs

Assignment Write a Java program consisting of the five related classes presented in the UML diagram on the next page. Please note that what looks like a‘0’ following toString and calcPay methods in the UML class diagrams are empty parentheses.1.

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

  1. Complete the assignment with Lab9.java, which contains main and which is posted with this assignment11. Upload Employee.java, Salaried.java, Waged.java, Sales.java and Address.java to WSU Online for grading – please do not zip the files

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