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)
- Java languagearrow_forwardExercise 2: A. Write static methods: public static double cubeVolume(double h) : h3 public static double cubeSurface(double h) : 6h2 public static double cylinderVolume(double r, double h) : har2 public static double cylinderSurface(double r, double h) : 2rnh+ 2nr2 that compute the volume and surface area of a cube with height h, and a cylinder with circular base with radius r and height h. Place them into a class named "Geometry.java". Then write a program with main class called "Lab7 yourlID.java" that prompts the user for the values of r and h, calls the four methods, and prints the results. ondarrow_forwardwrite easy java programsarrow_forward
- Exercise 3: A. Write static methods: public static double sphereVolume(double r) :Tr3 public static double sphereSurface(double r) : 4ar2 public static double coneVolume(double r, double h): – thr² public static double coneSurface(double r, double h) :7r(h+r) 1 3 that compute the volume and surface area of a sphere with radius r, and a cone with circular base with radius r and height h. Place them into a class "Geometry2.java". Then write a program with main class called "Lab7_yourID.java" that prompts the user for the values of r and h, calls the four methods, and prints the results. B. (Optional) Reconsider your previous solution by implementing classes Sphere, and Cone separately instead of a single class "Geometry2" (part A). Which approach is more object-oriented? Extra Geometry to try: Area of Plane Shapes Area is the size of a surface! Learn more about Area, or try the Area Calculator. Triangle Area = 2 x b x h b = base h = vertical height Square Area = a? a = length of side a b…arrow_forwardUsing java scannerarrow_forwardA constructor that creates a regular polygon with the specified number of sides, length of side, and x-and y-coordinates. • The method getPerimeter() that returns the perimeter of the polygon. The formula for computing the perimeter of a regular polygon is: p=s.n • The method getArea() that returns the area of the polygon. The formula for computing the area of a regular polygon is n x s? Area = 4 X tan n Write a test program that creates three RegularPolygon objects, using the no-arg constructor, using RegularPolygon(6, 4), and using RegularPolygon(10, 4, 5.6, 7.8). For each object, display its perimeter and area.arrow_forward
- Exercise 3: A. Write static methods: • public static double sphereVolume(double r) :r3 • public static double sphereSurface(double r) : 47tr? • public static double coneVolume(double r, double h): – thr² public static double coneSurface(double r, double h) :7r(h +r) that compute the volume and surface area of a sphere with radius r, and a cone with circular base with radius r and height h. Place them into a class “Geometry2.java". Then write a program with main class called “Lab7_yourlD.java" that prompts the user for the values of r and h, calls the four methods, and prints the results.arrow_forwardJava . With screen shot pleasearrow_forwardpublic class Polygon { private double sideLength; private int sides; private String shape; public double getArea () { int n sides; double a sideLength; return ((a * a * n) / (4 * Math.tan((180 / n) 3.14159 / 180))); public void setPolygon (double sl, int sd, String sh) { sides-sd; sideLength-sl; shape=sh; public Polygon (double sl, int sd, String sh) ( sides-sd; sideLengthsl; shape=sh; public String getShape () { return (shape); } public int getSides () { return (sides); } public double getLength () { return (sideLength); } Write a static method named find that takes as a parameter an array of type Polygon named list. The method should print the shapes of each polygon that has an area greater than 500 and return their count. The method prototype is public static int find (Polygon [] list); Note: assume the array is already declared, populated with data in the main method and ready to be used.arrow_forward
- Design an application that does the following: A Solid can be a FlatSurfaceSolid or a CurvedSurfaceSolid. Every solid will have a volume. The method volume will be polymorphic. A solid has faces, vertices and edges. A flat-surface solid also has a variable called side which represents the length of the side. A curved-surface solid also has a radius. A Cube is a FlatSurfaceSolid. A cube has 6 faces, 8 vertices and 12 edges. It will have a side. A Sphere is a CurvedSurfaceSolid. It has 1 face, 0 vertices and 0 edges. It will have a radius. Create an ArrayList of solids (driver file named YourLastNameCISC231Q1.java). The arraylist will have 4 elements – 2 cubes (one with side length 3 and another will side length 4) and 2 spheres (one with radius 3 and another with radius 4). Create a driver class to instantiate an array of solids and display the details of each solid along with the volume of each solid.arrow_forward21. Consider the following method: public static void sketch(int x1, int y1, int x2, int y2, int n) ( if (n <= 0) O else ( } drawLine(x1, y1, x2, y2); Assume that the screen looks like a Cartesian coordinate system with the origin at the center, and that drawLine connects (x1,y1) to (x2,y2). Assume also that x1, y1, x2, and y2 are never too large or too small to cause errors. Which picture best represents the sketch drawn by the method call int xm (x1 + x2 + y1 - y2) / 2; int ym (y1 + y2 + x2-x1) / 2; sketch(x1, y1, xm, ym, n - 1); sketch (xm, ym, x2, y2, n - 1); sketch(a, 0, -a, 0, 2) where a is a positive integer? (A) <-a y -a y a X (B) (D) -a -a y + -a -a aarrow_forwardImplement the following two methods:/** Return true if the sum of every two sides is* greater than the third side. */public static boolean isValid(double side1, double side2, double side3) /** Return the area of the triangle. */public static double area(double side1, double side2, double side3)Write a test program that reads three sides for a triangle and uses the isValidmethod to test if the input is valid and uses the area method to obtain the area.The program displays the area if the input is valid. Otherwise, it displays thatthe input is invalid.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