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, 22.06.2019 17:30
1. before plugging in a new device to a computer you should unplug all other devices turn off the computer turn on the computer 2. many of the maintenance tools for a computer can be found in the control panel under administrative tools display personalization
Answers: 1
question
Computers and Technology, 23.06.2019 16:10
What is the ooh? a. omaha occupation handbook b. online occupational c. occupations online d. occupational outlook handbook select the best answer from the choices provided
Answers: 3
question
Computers and Technology, 24.06.2019 00:40
What is the error in the following pseudocode? module main() call raisetopower(2, 1.5) end module module raisetopower(real value, integer power) declare real result set result = value^power display result end module
Answers: 1
question
Computers and Technology, 24.06.2019 09:30
Retype the statements, correcting the syntax errors. system.out.println("num: " + songnum); system.out.println(int songnum); system.out.println(songnum " songs"); note: these activities may test code with different test values. this activity will perform two tests: the first with songnum = 5, the second with songnum = 9. see how to use zybooks.
Answers: 1
You know the right answer?
Given the Solid class, extend it with: Pyramid
Cylinder
RectangularPrism
Spher...
Questions
question
Mathematics, 23.04.2020 01:23
question
English, 23.04.2020 01:23
question
Mathematics, 23.04.2020 01:24
question
Mathematics, 23.04.2020 01:24
Questions on the website: 13722362