subject

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.
import java. lang. Math;
public class Pyramid extends Solid
{
// Code goes here
}
public class Cube extends RectangularPrism
{

// Code goes here
}
public class RectangularPrism extends Solid
{
// 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 Sphere extends Solid
{
// Code goes here
}
import java. lang. Math;
public class Cylinder extends Solid
{

// Code goes here
}
public class SolidTester
{
public static void main(String[] args)
{
String name;
double volume;
double surfaceArea;
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 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 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 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 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;
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 13:10
What is domain name system (dns)? allows dynamic ip address allocation so users do not have to have a preconfigured ip address to use the network converts ip addresses into domains, or identifying labels that use a variety of recognizable naming conventions the efficient coexistence of telephone, video, and data communication within a single network, offering convenience and flexibility not possible with separate infrastructures the integration of communication channels into a single service
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
What are the 12 colors of the spectrum called?
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
Me ajude por favor , coloquei uma senha e não consigo tira-la no chorme
Answers: 2
question
Computers and Technology, 24.06.2019 01:30
How would you cite different books by the same author on the works cited page? moore, jack h. folk songs and ballads. salem: poetry press, 1999. print. moore, jack h. ballads in poetry – a critical review. dallas: garden books, 1962. print. moore, jack h. folk songs and ballads. salem: poetry press, 1999. print. –––. ballads in poetry – a critical review. dallas: garden books, 1962. print. moore, jack h. ballads in poetry – a critical review. dallas: garden books, 1962. print. moore, jack h. folk songs and ballads. salem: poetry press, 1999. print. moore, jack h. ballads in poetry – a critical review. dallas: garden books, 1962. print. –––. folk songs and ballads. salem: poetry press, 1999. print.
Answers: 2
You know the right answer?
Given the Solid class, extend it with: Pyramid
Cylinder
RectangularPrism
Spher...
Questions
question
Mathematics, 13.09.2019 01:20
Questions on the website: 13722367