Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
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.
-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