Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Driver Class: import java.util.ArrayList; import java.util.List; public class Project2 { public static void main(String[] args) { /*ThreeDimensionalShape sphere = new Sphere(2.0); ThreeDimensionalShape cube = new

image text in transcribedimage text in transcribedimage text in transcribed

Driver Class:

import java.util.ArrayList;

import java.util.List;

public class Project2 {

public static void main(String[] args) {

/*ThreeDimensionalShape sphere = new Sphere(2.0);
ThreeDimensionalShape cube = new Cube(5.0);
ThreeDimensionalShape cylinder = new Cylinder(4.0, 1.0);
List shapes = new ArrayList();
shapes.add(sphere);
shapes.add(cube);
shapes.add(cylinder);
shapes.forEach(System.out::println);*/
Sphere sphere = new Sphere(2.0);
System.out.println(sphere);
}
}

Sphere Class:

public class Sphere {
private double radius;
public Sphere() {
super();
this.radius = 0.0;
}
public Sphere(double v) {
super();
this.radius = v;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double surfaceArea() {
return 4.0 * Math.PI * Math.pow(radius, 2);
}
public double volume() {
return (4.0/3.0) * Math.PI * Math.pow(radius, 3);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Sphere {");
sb.append("radius=").append(radius);
sb.append(", surface area=").append(surfaceArea());
sb.append(", volume=").append(volume());
sb.append('}');
return sb.toString();
}
}
Design and implement a set of classes that define a series of three-dimensional geometric shapes. The design is entirely up to you, but must include the following... For each shape, store fundamental data about its size and provide methods to access and modify this data. For each shape, provide appropriate methods to compute each shape's surface area and volume given the appropriate inputs. Your design must include at least one abstract class and one interface (but may include more if desired.) In your design, consider how shapes are related and thus where inheritance can be implemented. Modify the driver class provided to instantiate several shapes of differing types and exercise the behavior you provided. (i.e. print out it's state using the toString() method.) You should implement at least four shapes, including a sphere, which is given. Hint: There are many different types of 3 dimensional geometric shapes to include in your design. Try Googling 'list of 3d shapes' and see what you can come up with! The toString() method should print the name of the shape, its volume, and its surface area. Take a look at the sphere class for an example of how this is done. Hint: Use the auto-generate feature in the IDE to generate the toString() method and add the necessary data to it. An example of a 3 shape design is given below. You may use these names and/or shapes or come up with your own appropriate naming convention. It's up to you! Once you get your code working, when you run the driver, you should see something similar to the following: Sphere { radius =2.0, surface area =50.26548245743669, volume =33.510321638291124} Cube { width =5.0, surface area =150.0, volume =125.0} Cylinder \{height =4.0, radius =1.0, surface area=31.41592653589793, volume =12.566370614359172}

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago