Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can I get some help in JAVA , i uploaded starter code, the subclasses that should be done, and the detailed question 4 5 public

Can I get some help in JAVA , i uploaded starter code, the subclasses that should be done, and the detailed question

image text in transcribedimage text in transcribedimage text in transcribed

4 5 public class Main 6 public static void main(String[] args) Shape snew Shape [10]; s [01new Triangle (new Vertex(1.0, 2.0), new Vertex(4.0, 4.0), new Vertex(5.0, 0)); System.out.println (s [0].toString)) 8 10 12 13 class Vertex 14 15e 16 17 18e 19 20 21 public double x, y, z; public Vertex (double_x, double_y) public Vertex (double_x, double_y, double_z) 23 class Shape 24 25e 26 27 28 29 public Vertex[ va; public double distance(Vertex a, Vertex b) f return Math.sqrt (Math.pow(a.x-b.x, 2)Math.pow(a.y - b.y, 2)); 30 class Triangle extends Shape implements PerimeterMeasurable, AreaMeasureablet 31 public Triangle(Vertex v1, Vertex v2, Vertex v3) 32 va- new Vertex [3]; 34 35 public String toString)t 36 37 38 39 40 public double getPerimeter) ( 41 42 43 String str = "'' ; str "Perimeter: "+getPerimeter)+"n"; return str; double perimeter-0; perimeter distance (va [0],va [1]); perimeter += distance(va[1] , va [2]); perimeter distance(va [2] , va [0]); return perimeter; 45 46 47 48 49 interface PerimeterMeasurable 50 51 52 53 interface AreaMeasureable ( 54 public abstract double getPerimeter); 56 57 interface VolumeMeasurable 58 59 Define a class structure that models a shape hierarchy. Shape base class for any kind of shape, holds an array of vertices o PlaneShape base class for all plane (2D) shapes, holds a array of 2D vertices (holding x and y), implements PerimeterMeasurable and AreaMeasurable interfaces Triangle - holds 3 vertices Rectangle-holds 1 vertex, width, height Circle - holds 1 vertex and radius o SpaceShape base class for all three-dimensional shapes, holds an array of 3D vertices (holding x, y and z), implements AreaMeasurable and VolumeMeasurable interfaces Square Pyramid holds 1 vertex (base center), base width, pyramid height Cuboid - holds 1 vertex, width, height, depth Sphere - holds 1 vertex and radius A vertex is a point in 2D/3D space. The distance between two 2D vertices is calculated using the formula: Define the following interfaces: .PerimeterMeasurable - holds double getPerimeter() AreaMeasurable - holds double getArea() VolumeMeasurable - holds double getVolume() Design the class hierarchy using proper inheritance and code reusability through abstraction. Each shape should implement its respective interfaces with proper formulas. Override toString() to return information about each shape (shape type, each vertex's coordinates, perimeter/area/volume). Create objects of different classes and add them to a single array. Iterate through the array and print information about each shape. Superclass Shape SublassT Triangle Rectangle Cicle SauarePyra mid Cuboid Sphere mid Cuboid Sphere 4 5 public class Main 6 public static void main(String[] args) Shape snew Shape [10]; s [01new Triangle (new Vertex(1.0, 2.0), new Vertex(4.0, 4.0), new Vertex(5.0, 0)); System.out.println (s [0].toString)) 8 10 12 13 class Vertex 14 15e 16 17 18e 19 20 21 public double x, y, z; public Vertex (double_x, double_y) public Vertex (double_x, double_y, double_z) 23 class Shape 24 25e 26 27 28 29 public Vertex[ va; public double distance(Vertex a, Vertex b) f return Math.sqrt (Math.pow(a.x-b.x, 2)Math.pow(a.y - b.y, 2)); 30 class Triangle extends Shape implements PerimeterMeasurable, AreaMeasureablet 31 public Triangle(Vertex v1, Vertex v2, Vertex v3) 32 va- new Vertex [3]; 34 35 public String toString)t 36 37 38 39 40 public double getPerimeter) ( 41 42 43 String str = "'' ; str "Perimeter: "+getPerimeter)+"n"; return str; double perimeter-0; perimeter distance (va [0],va [1]); perimeter += distance(va[1] , va [2]); perimeter distance(va [2] , va [0]); return perimeter; 45 46 47 48 49 interface PerimeterMeasurable 50 51 52 53 interface AreaMeasureable ( 54 public abstract double getPerimeter); 56 57 interface VolumeMeasurable 58 59 Define a class structure that models a shape hierarchy. Shape base class for any kind of shape, holds an array of vertices o PlaneShape base class for all plane (2D) shapes, holds a array of 2D vertices (holding x and y), implements PerimeterMeasurable and AreaMeasurable interfaces Triangle - holds 3 vertices Rectangle-holds 1 vertex, width, height Circle - holds 1 vertex and radius o SpaceShape base class for all three-dimensional shapes, holds an array of 3D vertices (holding x, y and z), implements AreaMeasurable and VolumeMeasurable interfaces Square Pyramid holds 1 vertex (base center), base width, pyramid height Cuboid - holds 1 vertex, width, height, depth Sphere - holds 1 vertex and radius A vertex is a point in 2D/3D space. The distance between two 2D vertices is calculated using the formula: Define the following interfaces: .PerimeterMeasurable - holds double getPerimeter() AreaMeasurable - holds double getArea() VolumeMeasurable - holds double getVolume() Design the class hierarchy using proper inheritance and code reusability through abstraction. Each shape should implement its respective interfaces with proper formulas. Override toString() to return information about each shape (shape type, each vertex's coordinates, perimeter/area/volume). Create objects of different classes and add them to a single array. Iterate through the array and print information about each shape. Superclass Shape SublassT Triangle Rectangle Cicle SauarePyra mid Cuboid Sphere mid Cuboid Sphere

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 9th International Conference Dasfaa 2004 Jeju Island Korea March 2004 Proceedings Lncs 2973

Authors: YoonJoon Lee ,Jianzhong Li ,Kyu-Young Whang

2004th Edition

3540210474, 978-3540210474

More Books

Students also viewed these Databases questions

Question

What is Accounting?

Answered: 1 week ago

Question

Define organisation chart

Answered: 1 week ago

Question

What are the advantages of planning ?

Answered: 1 week ago

Question

Explain the factors that determine the degree of decentralisation

Answered: 1 week ago