Concept explainers
Write methods
public static double sphereVolume(double r)
public static double sphereSurface(double r)
public static double cylinderVolume(double r, double h)
public static double cylinderSurface(double r, double h)
public static double coneVolume(double r, double h)
public static double coneSurface(double r, double h)
that compute the volume and surface area of a sphere with radius r, a cylinder with a circular base with radius r and height h, and a cone with a circular base with radius r and height h. Then write a
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (4th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- 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 orderPyramid 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 radiusSphere sphere = new Sphere("My sphere", 4);name = sphere.getName();volume = round(sphere.volume(), 2);surfaceArea =…arrow_forwardjava program Write the equals method for Circle2 which returns true when the radius and the color are the same as the parameter’s radius and color. The TestCircle2, Circle2 and GeometricObject2 classes are given as follows. public class TestCircle2 { public static void main(String[] args) { Circle2 c1 = new Circle2(2.3, "red"); Circle2 c2 = new Circle2(5.6, "white"); Circle2 c3 = new Circle2(2.3, "red"); System.out.println("c1 equals c2: " + c1.equals(c2)); System.out.println("c1 equals c3: " + c1.equals(c3)); System.out.println("c2 equals c3: " + c2.equals(c3)); } } class Circle2 extends GeometricObject2 { private double radius; public Circle2() { } public Circle2(double radius) { this.radius = radius; } public Circle2(double radius, String color) { this.radius = radius; setColor(color); } /** * Return radius */ public double getRadius()…arrow_forwardImplement a class that simulates a traffic light. The next method advances the color in the usual way, from green to yellow to red, then again to green. Provide two constructors, as described in the documentation of the public interface. Also supply a method that yields the number of times that this traffic light has been red. /** A simulated traffic light.*/public class TrafficLight{ private String color; private int reds; /** Constructs a green traffic light. */ public TrafficLight() { /* Your code goes here */ } /** Constructs a traffic light. @param initialColor the initial color "green", "yellow", or "red" */ public TrafficLight(String initialColor) { /* Your code goes here */ } /** Moves this traffic light to the next color. */ public void next() { /* Your code goes here */ } /** Returns the current color of this traffic light. @return the current color */ public String getColor() {…arrow_forward
- Please solve this using java and attach output screenshot and implementation screenshot. Using this clock class please: public class Clock { private int hr; private int min; private int sec; public Clock() { setTime(0, 0, 0); } public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); } public void setTime(int hours, int minutes, int seconds) { if (0 <= hours && hours < 24) hr = hours; else hr = 0; if (0 <= minutes && minutes < 60) min = minutes; else min = 0; if(0 <= seconds && seconds < 60) sec = seconds; else sec = 0; } public int getHours() { return hr; } public int getMinutes() { return min; } public int getSeconds() { return sec; } public void printTime() { if (hr < 10) System.out.print("0"); System.out.print(hr + ":"); if (min < 10) System.out.print("0"); System.out.print(min + ":"); if (sec < 10) System.out.print("0"); System.out.print(sec); } public void incrementSeconds() { sec++; if (sec >…arrow_forward4.2.3: Method definition: Volume of a pyramid. Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations: Volume = base area x height x 1/3Base area = base length x base width.(Watch out for integer division). import java.util.Scanner; public class CalcPyramidVolume { //answer goes here// public static void main (String [] args) { Scanner scnr = new Scanner(System.in); double userLength; double userWidth; double userHeight; userLength = scnr.nextDouble(); userWidth = scnr.nextDouble(); userHeight = scnr.nextDouble(); System.out.println("Volume: " + pyramidVolume(userLength, userWidth, userHeight)); }}arrow_forwardWrite a Rectangle class to represent rectangles, with two data fields (width, height) and four methods (input data, display data, calculate and return area, calculate and return perimeter). Write another class to test all methods of the Rectangle class.arrow_forward
- Can someone complete this implementation of interface class in JAVA public class Main{ public static void main(String[] args) { Shape s = new Square(2); Shape r = new Rectangle(4,2); Shape t = new Triangle(3,3); // Your test code here }} -------- public interface Shape{ public float Area(); public float Perimeter(); public String Shapetype();} ------ public class Rectangle implements Shape{ } ------------ public class Square implements Shape{ } ----------- public class Triangle implements Shape{ } ------------arrow_forwardThis question was rejected from incompletion but it's completed. Answer the prompt with the following code as a guide for the main method: import java.awt.*; public class TestRectangle { public static void main(String[] args) { Rectangle r1 = new Rectangle(5, 4, 10, 17); Rectangle r2 = new Rectangle(10, 10, 20, 3); Rectangle r3 = new Rectangle(0, 1, 12, 15); Rectangle r4 = new Rectangle(10, 10, 20, 3); System.out.println("r1 = " + r1); System.out.println("r2 = " + r2); System.out.println("r3 = " + r3); System.out.println("r2 equals r1? " + r2.equals(r1)); System.out.println("r2 equals r2? " + r2.equals(r2)); System.out.println("r2 equals r3? " + r2.equals(r3)); System.out.println("r2 equals r4? " + r2.equals(r4)); System.out.println("r1 contains (6, 8)? = " + r1.contains(6, 8)); System.out.println("r2 contains (6, 8)? = " + r2.contains(6, 8));…arrow_forwardAdd the following constructor to your Rectangle class: public Rectangle(Point p, int width, int height) Construct a new Rectangle whose top-left corner is specified by the given Point and with the given width and height.arrow_forward
- Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations: Volume = base area x height x 1/3Base area = base length x base width.(Watch out for integer division). import java.util.Scanner; public class CalcPyramidVolume { /* Your solution goes here */ public static void main (String [] args) {Scanner scnr = new Scanner(System.in);double userLength;double userWidth;double userHeight; userLength = scnr.nextDouble();userWidth = scnr.nextDouble();userHeight = scnr.nextDouble(); System.out.println("Volume: " + pyramidVolume(userLength, userWidth, userHeight));}}arrow_forwardWrite a class CircularArrayQueue such that all the following methods are implemented: 1. enqueue 2. dequeue 3. first 4. isEmpty 5. size 6. toStringarrow_forwardFor this problem you will write a method that computes the number of boxes in a pyramid of boxes based on the number of boxes in the base. The boxes in each layer of the pyramid are stacked directly on top of one another (i.e. not offset between two boxes below). For example, below are shown two pyramids, one with base 5 and one with base 6. [] [][] [][][] [][][][] [][][][][] [][][][][][] Implement and test the computePyramidBoxes() method in the PyramidBoxCount class. When testing the computePyramidBoxes() method you should be sure to have at least one test method for each base case and at least one test method for each recursive case in your program.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education