Workshop #5: Polymorphism: Learning Outcomes
Workshop #5: Polymorphism: Learning Outcomes
Workshop #5: Polymorphism: Learning Outcomes
Learning Outcomes:
Upon successful completion of this workshop, you will have demonstrated the abilities
to:
Practice polymorphism.
Understand the principles and the use of abstract classes and interfaces in Java
Describe to your instructor what you have learned in completing this workshop.
Part 1: [7 points]
Using Java language to build an application. This app is an example to expose parts of
your classes. Consider the class diagram as follows:
<<abstract class>>
Organization
# size: int
+ Organization ()
+ Organization (String)
+ getSize():int
+ setSize(int):void
+ communicateByTool(): void, abstract
+ toString():String
Colony University
FPTUniversity
BeeColony
address: String
type: String (honey/wasp)
+ FPTUniversity ()
+ FPTUniversity (int, String, String)
+ BeeColony () + gettter/setter
+ BeeColony (int, String, String) + toString():String
+ gettter/setter
+ toString():String
1
The Organization class contains the “communicateByTool()” method. This method
describes the communication way between members. For now, we don’t have any
information to implement it, so it should be the abstract method.
The Colony class and University class will extend the Organization class, they must
override the “communicateByTool()” method.
The BeeColony class and FPTUniversity class have got quite different inheritance
hierarchies. But both create workers and they don't share much in common. So, we
declare an interface named “Role” that contains the “createWorker()” common method.
These classes will implement it.
To complete this task you will implement the class structure above
Step 3: Create another package named “GUI”, it contains the Tester.java file
Requirements:
This class extends the Colony class and implements the Role interface
2
The method toString(): return the string as format:
“the colony’s type is ” + the value of the type field+ “, size is about” + the value of the size field + “,
and the place is” + the value of place field
The createWorker() method: must be overridden to print out the string as
“Worker bees perform all the work of the bees”
This class extends the University class and implements the Role interface
The method toString(): return the string as format: “FPTU has four campuses Hanoi,
HCM, DaNang, CanTho, QuyNhon”
The createWorker() method: must be overridden to print out the string as
“providing human resources”
3
Part 2: Draw the memory map when the program runs [3 points]
Explain step by step what happened when the program runs and answer some questions.