Given the Solid class, extend it with: Pyramid Cylinder RectangularPrism Sphere Make sure to create the constructor and override the volume and surfaceArea methods. Also extend RectangularPrism with Cube. HINT: You can look up formulas for how to compute the volume and surface area of a certain type of shape online. ========================================== public class SolidTester { public static void main(String[] args) { String name; double volume; double surfaceArea; // Pyramid constructor should take name, length, width, height // in that order Pyramid pyramid = new Pyramid("My pyramid", 1, 3, 5); name = pyramid.getName(); volume = round(pyramid.volume(), 2); surfaceArea = round(pyramid.surfaceArea(), 2); System.out.println("Pyramid '" + name + "' has volume: " + volume + " and surface area: " + surfaceArea + "."); // Sphere constructor should take name then radius Sphere sphere = new Sphere("My sphere", 4); name = sphere.getName(); volume = round(sphere.volume(), 2); surfaceArea = round(sphere.surfaceArea(), 2); System.out.println("Sphere '" + name + "' has volume: " + volume + " and surface area: " + surfaceArea + "."); // RectangularPrism constructor should take name, // length, width, height in that order RectangularPrism rectangularPrism = new RectangularPrism("My rectangular prism", 5, 8, 3); name = rectangularPrism.getName(); volume = round(rectangularPrism.volume(), 2); surfaceArea = round(rectangularPrism.surfaceArea(), 2); System.out.println("RectangularPrism '" + name + "' has volume: " + volume + " and surface area: " + surfaceArea + "."); // Cylinder constructor should take name, radius, height // in that order Cylinder cylinder = new Cylinder("My cylinder", 4, 9); name = cylinder.getName(); volume = round(cylinder.volume(), 2); surfaceArea = round(cylinder.surfaceArea(), 2); System.out.println("Cylinder '" + name + "' has volume: " + volume + " and surface area: " + surfaceArea + "."); // Cube constructor should take name then side length Cube cube = new Cube("My cube", 4); name = cube.getName(); volume = round(cube.volume(), 2); surfaceArea = round(cube.surfaceArea(), 2); System.out.println("Cube '" + name + "' has volume: " + volume + " and surface area: " + surfaceArea + "."); } public static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); long factor = (long) Math.pow(10, places); value = value * factor; long tmp = Math.round(value); return (double) tmp / factor; } } ========================================== public class RectangularPrism extends Solid { // Code goes here } ========================================== import java.lang.Math; public class Sphere extends Solid { // Code goes here } ========================================== import java.lang.Math; public class Pyramid extends Solid { // Code goes here } ========================================== public class Cube extends RectangularPrism { // Code goes here } ========================================== public class Solid { private String myName; public Solid(String name) { myName = name; } public String getName() { return myName; } // This should be overriden in the subclass public double volume() { return 0; } // This should be overriden in the subclass public double surfaceArea() { return 0; } } ========================================== import java.lang.Math; public class Cylinder extends Solid { // Code goes here }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Given the Solid class, extend it with:

Pyramid Cylinder RectangularPrism Sphere

Make sure to create the constructor and override the volume and surfaceArea methods.

Also extend RectangularPrism with Cube.

HINT: You can look up formulas for how to compute the volume and surface area of a certain type of shape online.

==========================================

public class SolidTester
{
public static void main(String[] args)
{
String name;
double volume;
double surfaceArea;

// Pyramid constructor should take name, length, width, height
// in that order
Pyramid pyramid = new Pyramid("My pyramid", 1, 3, 5);
name = pyramid.getName();
volume = round(pyramid.volume(), 2);
surfaceArea = round(pyramid.surfaceArea(), 2);
System.out.println("Pyramid '" + name + "' has volume: " + volume +
" and surface area: " + surfaceArea + ".");

// Sphere constructor should take name then radius
Sphere sphere = new Sphere("My sphere", 4);
name = sphere.getName();
volume = round(sphere.volume(), 2);
surfaceArea = round(sphere.surfaceArea(), 2);
System.out.println("Sphere '" + name + "' has volume: " + volume +
" and surface area: " + surfaceArea + ".");

// RectangularPrism constructor should take name,
// length, width, height in that order
RectangularPrism rectangularPrism = new RectangularPrism("My rectangular prism",
5, 8, 3);
name = rectangularPrism.getName();
volume = round(rectangularPrism.volume(), 2);
surfaceArea = round(rectangularPrism.surfaceArea(), 2);
System.out.println("RectangularPrism '" + name + "' has volume: " +
volume + " and surface area: " + surfaceArea + ".");

// Cylinder constructor should take name, radius, height
// in that order
Cylinder cylinder = new Cylinder("My cylinder", 4, 9);
name = cylinder.getName();
volume = round(cylinder.volume(), 2);
surfaceArea = round(cylinder.surfaceArea(), 2);
System.out.println("Cylinder '" + name + "' has volume: " + volume +
" and surface area: " + surfaceArea + ".");

// Cube constructor should take name then side length
Cube cube = new Cube("My cube", 4);
name = cube.getName();
volume = round(cube.volume(), 2);
surfaceArea = round(cube.surfaceArea(), 2);
System.out.println("Cube '" + name + "' has volume: " + volume +
" and surface area: " + surfaceArea + ".");
}

public static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();

long factor = (long) Math.pow(10, places);
value = value * factor;
long tmp = Math.round(value);
return (double) tmp / factor;
}
}

==========================================

public class RectangularPrism extends Solid
{

// Code goes here
}

==========================================

import java.lang.Math;

public class Sphere extends Solid
{

// Code goes here
}

==========================================

import java.lang.Math;

public class Pyramid extends Solid
{

// Code goes here
}

==========================================

public class Cube extends RectangularPrism
{

// Code goes here
}

==========================================

public class Solid
{
private String myName;

public Solid(String name)
{
myName = name;
}

public String getName()
{
return myName;
}

// This should be overriden in the subclass
public double volume()
{
return 0;
}

// This should be overriden in the subclass
public double surfaceArea()
{
return 0;
}
}

==========================================

import java.lang.Math;

public class Cylinder extends Solid
{

// Code goes here
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education