Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the concept of polymorphism, implement the shape hierarchyshown in figure

ID: 3618820 • Letter: U

Question

Using the concept of polymorphism, implement the shape hierarchyshown in figure 9.3(Circle and Triangle are subclasses oftwoDimensionalShapes which is a subclassof Shape andCube is a subclass of ThreeDimensionalShapes which is asubclass of Shape) (neglect the Sphere, Tetrahedron, andSquare). Each TwoDimensionalshape should contain method getArea tocalculate the area of the shape. Each ThreeDimensionalShape shouldhave methods getArea and getVolume to calculate the surface areaand the volume of the shape. Create a program that uses an array ofshapes references to objects of each class in the hierarchy. Theprogram should print a text description of the object to which eacharray element refers. Also, in the loop that processes all theshapes in the array; determine whether the shape isTwodimensionalShape or Threedimensionalshape by displaying the areaonly, or the area and the volume.

“shapes.txt”

Circle   3

Triangle   4 5

Cube   6

  

“results.txt”

The area of the Circle is:  

The area of the Triangle is:  

The area of the Cube is:       andthe volume is:

Make sure to handle all possible exceptions in your program.

“shapes.txt”

Circle   3

Triangle   4 5

Cube   6

  

Explanation / Answer

I don't have enough time to complete itbut here is the driver class where you read a file and get itcontents. Hope this will helpyou. import java.io.*; import java.util.StringTokenizer; import javax.swing.*; public class Main{ public static void main(String[] args) {     JFrame frame = new JFrame("Project");    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     JFileChooser fileChooser = newJFileChooser();     fileChooser.setDialogTitle("Choose a file");     frame.getContentPane().add(fileChooser);     fileChooser.setVisible(true);        int returnVal =fileChooser.showOpenDialog(frame);     if(returnVal == JFileChooser.APPROVE_OPTION){        System.out.println("You choseto open this file: " +            fileChooser.getSelectedFile().getName());     }     File selectedFile =fileChooser.getSelectedFile();     try {            //FileInputStream fis = new FileInputStream(selectedFile);            int b;            String fileData = "";            BufferedReader in = new BufferedReader(newFileReader(selectedFile));            String str;            while ((str = in.readLine()) != null) {                StringTokenizer st = new StringTokenizer(str);                while (st.hasMoreTokens()) {                        System.out.println(st.nextToken());                }            }            in.close();            System.out.println(fileData);         } catch(FileNotFoundException ex)            {                ex.printStackTrace();            }          catch (IOExceptionex)            {                ex.printStackTrace();            }     frame.pack();     frame.setVisible(true); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote