Lab 1: Java Program for Class Relationships and Multi-Class Programs - Prof. Delroy Brinke, Lab Reports of Computer Science

An assignment for creating a java program consisting of five related classes based on the uml diagram provided. The assignment requires making all instance variables private, making all classes public, initializing instance variables via constructor calls, and implementing tostring and calcpay methods. The employee class is made abstract, and salaried, waged, and sales classes are derived from it. The objective is to push data into the objects using constructor calls and pull data out using tostring and calcpay methods.

Typology: Lab Reports

Pre 2010

Uploaded on 07/23/2009

koofers-user-t2r
koofers-user-t2r 🇺🇸

5

(2)

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab #1
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 instance variables (i.e., attributes) private
2. Make all classes public (each class in its own file)
3. Initialize all instance variables via constructor calls
4. Each toString method should return a string representation of the calling object; this usually includes all instance variables contained in
the object and in any super classes. The format of the returned string is not important. The toString method should not print or display
the value of any variables - just concatenate and return them
5. class Employee (make this class abstract)
a. calcPay: make this method abstract
6. class Salaried
a. calcPay returns salary / 24
b. Format is not important
7. class Waged
a. calcPay returns hours * wage
b. Format is not important
8. 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
9. Complete the assignment with Lab1.java, which contains main and which is posted with this assignment
10. 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 Lab1.java is not needed. (Note that I will be using the posted version of Lab1.java, which implies that you should
not make changes to it.)
Note that the objective of this assignment is to “push” data into the objects with constructor calls and to “pull” data from the objects using
toString, calcPay.
pf2

Partial preview of the text

Download Lab 1: Java Program for Class Relationships and Multi-Class Programs - Prof. Delroy Brinke 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 instance variables (i.e., attributes) private

Make all classes public (each class in its own file)

Initialize all instance variables via constructor calls

Each toString method should return a string representation of the calling object; this usually includes all instance variables contained inthe object and in any super classes. The format of the returned string is not important. The toString method should not print or displaythe value of any variables - 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

Complete the assignment with Lab1.java, which contains main and which is posted with this assignment

  1. 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 Lab1.java is not needed. (Note that I will be using the posted version of Lab1.java, which implies that you shouldnot make changes to it.) Note that the objective of this assignment is to “push” data into the objects with constructor calls and to “pull” data from the objects usingtoString, calcPay.

-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