Question
Question 2 (10 marks) This question will test your ability to use: Inheritance, exception handling and object file processing The following UML diagram shows the
Question 2 (10 marks)
This question will test your ability to use: Inheritance, exception handling and object file processing
The following UML diagram shows the relationship of three unknown shapes:
The main objective of this question is to assume that all classes implement the Serializable interface so that you can construct and process serializable objects.
The class Shape_1 has only one instance variable a (double type). Based on this instance variable, we can imagine a to be the radius of a circle object; it can also be the sides of a square (all the four sides are the same) and it can also be an equilateral triangle (all the three sides are the same).
The class Shape_2 is a subclass of Shape_1 has one more instance variable b. Implicitly we have two instance variables (a and b) in this class. We can imagine a and b can be the length and the width of a rectangle or the sides of an isosceles triangle (two sides are equal to a, the third side is b).
The class Shape_3 is a subclass of Shape_2 has one more instance variable c. Implicitly we have three instance variables (a, b, and c). We can imagine a, b and c are the three sides of a triangle or a parallelogram (two sides are a, the other two sides are b and c is the height, just like a trapezoid).
For each shape object, we can compute its area and its perimeter.
A toString method to return the String representation of each shapes object. For example, you can just return a, or a, b or a, b, c, respectively, for each of the three shapes.
When implementing these three classes, you dont have to cater for all possible shapes, you choose one specific shape for each class. For example, you can assume that objects constructed from class Shape_1 are just like circle objects; objects constructed from class Shape_2 are just like rectangle objects and objects constructed from class Shape_3 are just like triangle objects.
The most important of the question should be the main class. Here is the UML diagram:
Two important methods in the main class: create a file consists of some serializable objects and process the serializable file.
Upon execution, you will see the following interactions and displays:
In creation, you need to construct at least one object of each class and store them in an object file. All information are randomly generated:
In processing, you should let Java process it polymorphically. Here is the display:
Save all classes in a Java file called YourName_Supp_2.java and upload this Java file.
Question 2 (10 marks) This question will test your ability to use: Inheritance, exception handling and object file processing The following UML diagram shows the relationship of three unknown shapes: Shape_1 s double a +Shape_1(double a) + double area + double perimetero + String toStringo K Is Shape_2 #double b + Shape_2(double a, double b) + double area + double perimetero + String to Stringo Shape_3 - doublec + Shape_3(double a, double b, double c) + double area + double perimeter + String to Stringo The main objective of this question is to assume that all classes implement the Serializable interface so that you can construct and process serializable objects. The class Shape_1 has only one instance variable a (double type). Based on this instance variable, we can imagine a to be the radius of a circle object; it can also be the sides of a square (all the four sides are the same) and it can a also be an equilateral triangle all the three sides are the same). The main objective of this question is to assume that all classes implement the Serializable interface so that you can construct and process serializable objects. The class Shape_1 has only one instance variable a (double type). Based on this instance variable, we can imagine a to be the radius of a circle object; it can also be the sides of a square (all the four sides are the same) and it can also be an equilateral triangle (all the three sides are the same). The class Shape_2 is a subclass of Shape_1 has one more instance variable b. Implicitly we have two instance variables (a and b) in this class. We can imagine and b can be the length and the width of a rectangle or the sides of an isosceles triangle (two sides are equal to a, the third side is b). The class Shape_3 is a subclass of Shape_2 has one more instance variable c. Implicitly we have three instance variables (a, b, and c). We can imagine a band c are the three sides of a triangle or a parallelogram (two sides are a the other two sides are b and c is the height, just like a trapezoid). For each shape object, we can compute its area and its perimeter. A toString method to return the String representation of each shape's object. For example, you can just return a, or a, b or a, b, c, respectively, for each of the three shapes. When implementing these three classes, you don't have to cater for all possible shapes, you choose one specific shape for each class. For example, you can assume that objects constructed from class Shape_1 are just like circle objects; objects constructed from class Shape_2 are just like rectangle objects and objects constructed from class Shape_3 are just like triangle objects. The most important of the question should be the main class. Here is the UML diagram: Supp_2 3-static ObjectinputStream input -static ObjectOutputStream output -static double cetValue - static void createObjectFile(String fileName) + static void processObjectFile(String fileName) + static void main(Strinal args) Two important methods in the main class: create a file consists of some serializable objects and process the serializable file. Upon execution, you will see the following interactions and displays: In creation, you need to construct at least one object of each class and store them in an object file. All information are randomly generated: Begin creation of infile.ser ==> adding an object of Shape_1 to infile.ser ==> adding an object of Shape_2 to infile.ser ==> adding an object of Shape_3 to infile.ser Objects ready to write to infile.ser object file infile.ser successfully created In processing, you should let Java process it polymorphically. Here is the display: In processing, you should let Java process it polymorphically. Here is the display: Begin processing of infile.ser polymorphically Object is Shape_1 (1.817) Its area is 10.369 Its perimeter is 11.415 Object is Shape_2 (77.875, 96.413) Its area is 7431.084 Its perimeter is 346.977 Object is Shape_3 (69.749, 26.924, 74.745) Its area is 938.963 Its perimeter is 193.346 All objects processed *** Note that the following statements are printed in the finally block All tasks in Question 2 completed infile.ser closed for processing Save all classes in a Java file called Your Name_Supp_2.java and upload this Java fileStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started