Question: Attached is my previous code in java. package edu.LN.H2; abstract class Geom { protected String name; public Geom(String name) { this.name = name; } public

Attached is my previous code in java.

package edu.LN.H2;

abstract class Geom { protected String name;

public Geom(String name) { this.name = name; }

public abstract double getArea(); public abstract double getVolume();

public void printInfo() { System.out.println("Class name: " + this.name); System.out.println("Area: " + getArea()); System.out.println("Volume: " + getVolume()); } }

abstract class Geom2D extends Geom { public Geom2D(String name) { super(name); } }

abstract class Geom3D extends Geom { public Geom3D(String name) { super(name); } }

class Square extends Geom2D { private double side;

public Square(double side) { super("Square"); this.side = side; }

@Override public double getArea() { return side * side; }

@Override public double getVolume() { return 0; } }

class Circle extends Geom2D { private double radius;

public Circle(double radius) { super("Circle"); this.radius = radius; }

@Override public double getArea() { return Math.PI * radius * radius; }

@Override public double getVolume() { return 0; } }

class Cube extends Geom3D { private double side;

public Cube(double side) { super("Cube"); this.side = side; }

@Override public double getArea() { return 6 * side * side; }

@Override public double getVolume() { return side * side * side; } }

class Sphere extends Geom3D { private double radius;

public Sphere(double radius) { super("Sphere"); this.radius = radius; }

@Override public double getArea() { return 4 * Math.PI * radius * radius; }

@Override public double getVolume() { return (4.0 / 3.0) * Math.PI * radius * radius * radius; } }

class Tester { public static void main(String[] args) { Geom[] geoms = new Geom[] { new Square(2), new Circle(3), new Cube(4), new Sphere(5) };

for (Geom geom : geoms) { geom.printInfo(); System.out.println(); } } }

Copy the geometry package created to a new package named edu.LN.H3 and modify it to do the following: (1) Override the toString() method to generate a meaningful string that contains info about the geometry (implement at the lowest level in the inheritance hierarchy). (2) Override the equals() method so that you can compare any two objects of type Geom and the method should return true only if the objects are of the same type and have equal volume. (3) Create an interface called Relatable that implements public int isLargerThan(Relatable other). The this object calling isLargerThan() and the argument other need not be instances of the same class. The method should returns 1, 0, -1 if this has a volume greater than, equal to, or less than the volume of other. Implement this method for the Geom classes. (4) Add an abstract method for Geom called read(BufferedReader br) (5) Implement the read method for Geom classes and use it to read geometry from a file. (6) In the class called Tester create a main program for testing the above methods added to the Geometry package. Add a few more geometry Classes to the geometry package before testing (such as Rectangle and Cylinder). Create an ArrayList of Geom objects and add Geom objects to it that are created based on information read from a file. Loop over this ArrayList to test the methods by (a) printing out information about objects in the list using toString(), (b) searching to see if there is another geometry in the list that is equal to the first one in the list and (c) finding the largest and smallest geometry in the list using the isLargerThan() method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!