Question
In Java Write a java program creating one interface called Geometry. In geometry create three methods each returning a double value. Call them: double cube
In Java Write a java program creating one interface called Geometry. In geometry create three methods each returning a double value. Call them: double cube (double L) double sphere (double r) double cone (double r, double height) Implement the interface in two classes, one called Volume which calculates the volume of these geometries and one called Surface to calculate the surface area. In main calculate the volumes and surface areas of each using 4.0 for r, L, Height. Also calculate the surface area/ volume ratio for each. Verify that the sphere has the lowest surface area per volume ratio. Hint: Use hand out program given last time called "InterfaceDemoVolume" as template.
Interface demo volume
/*creating interface for Volume * Implementing Volume * uses interface reference */ package interfacedemovolume;
interface Volume{ double VolCube(double length); // returns volume of cube double Volsphere(double r);// returns volume of sphere double Volcone(double r, double height);// returns volume of cone double pi =3.1415; } class ImpVolume implements Volume { //Implements Volume and adds bodies to methods of interface double length,r,height; public double VolCube(double length) {return (Math.pow(length,3));} public double Volsphere(double r) {return ((4.0/3)*pi*Math.pow(r,3));} public double Volcone(double r, double height) {return (pi*r*r*height/3.0);} } public class InterfaceDemoVolume { public static void main(String[] args) { // ImpVolume cube1 = new ImpVolume(); ImpVolume sphere1 = new ImpVolume(); ImpVolume cone1 = new ImpVolume(); //cube1.length=4.0; sphere1.r = 4.0; cone1.r=4.0; cone1.height=4.0; System.out.println("Volume of cube: "+ cube1.VolCube(4.0)); System.out.println("Volume of sphere: "+ sphere1.Volsphere(4.0)); System.out.println("Volume of cone: "+ cone1.Volcone(4.0,4.0)); System.out.format("Volume of cone: %.3f%n", cone1.Volcone(4.0,4.0)); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started