Computers and Technology

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;
}
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 01:50, rhonda45801
Free points just awnser this. what should i watch on netflix
Answers: 2
image
Computers and Technology, 23.06.2019 09:30, kreshnikolloma
You wanted to look up information about alzheimer's, but you were unsure if it was spelled "alsheimer's" or "alzheimer's." which advanced search strategy would be useful? a) a boolean search b) using a wild card in your search c) trying different search engines d) doing a search for "alsheimer's not alzheimer's" asap. ill give brainlist.
Answers: 1
image
Computers and Technology, 23.06.2019 18:50, annieleblanc2004
Ais a picture icon that is a direct link to a file or folder
Answers: 1
image
Computers and Technology, 24.06.2019 00:20, danielmartinez024m
The guy wire bd exerts on the telephone pole ac a force p directed along bd. knowing the p must have a 720-n component perpendicular to the pole ac, determine the magnitude of force p and its component along line ac.
Answers: 2
Do you know the correct answer?
Given the Solid class, extend it with: Pyramid
Cylinder
RectangularPrism
Spher...

Questions in other subjects: