Workshop #4: Inheritance: Learning Outcomes
Workshop #4: Inheritance: Learning Outcomes
Workshop #4: Inheritance: Learning Outcomes
Learning Outcomes:
Upon successful completion of this workshop, you will have demonstrated the abilities to:
Requirements:
Part 1: [7 points]
To complete this task you should read and study the lecture Inheritance
Step 2: Create a package named “DTO”, it contains some files: Item.java, Vase.java,
Statue.java, and Painting.java
Step 3: Create another package named “GUI”, it contains the AntiqueShop.java file
1
Implement the class diagram as follows:
Item
#value: int
#creator: String
+Item()
+Item(int, String)
+getters/setters
+output():void
+input():void
AntiqueShop
+main():void
The AntiqueShop class is making use of Vase, Statue, and Painting, in the sense that it has declared references
to them, and thus there is a dependency.
Requirement:
1. In the file Item.java,
The method input(): Using Scanner class to input all fields of the Item class.
Verify: value>0, creator is not empty
2
Hint:
public class Vase{
…
//this method is used to input all fileds of a vase object
public void inputVase(){
input(); // call the inherited method to input two fields: value, creator
//TODO: you is required to add more your code to input two fields : height, material
// use try..catch/throws to handle exceptions
}
}while(choice<=4); }
5. (Optional) Now, you is required to update the above program. You should create a new
class named Menu. This class contains one static method
choice=Menu.getChoice(options);
switch(choice){
case 1:
item=new Vase();
((Vase)item).inputVase();
break;
….
}while(…);
}
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.