Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exercises
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("input object's radius:");
- double ra = scan.nextDouble();
- System.out.println("input object's height:");
- double he = scan.nextDouble();
- Geometry geometry = new Geometry();
- System.out.println("volume of cube:");
- System.out.println(geometry.cubeVolume());
- System.out.println("surface area of cube:");
- System.out.println(geometry.cubeSurface());
- System.out.println("volume of sphere:");
- System.out.println(geometry.sphereVolume());
- System.out.println("surface area of sphere:");
- System.out.println(geometry.sphereSurface());
- System.out.println("volume of cone:");
- System.out.println(geometry.coneVolume());
- System.out.println("surface area of cone:");
- System.out.println(geometry.coneSurface());
- System.out.println("volume of cylinder:");
- System.out.println(geometry.cylinderVolume());
- System.out.println("surface area of cylinder:");
- System.out.println(geometry.cylinderSurface());
- }
- }
- package chapter8;
- public class Geometry
- {
- private double height;
- private double radius;
- public Geometry(double h, double r)
- {
- height = h;
- radius = r;
- }
- public static double cubeVolume(double h)
- {
- return h * h * h;
- }
- public static double cubeSurface(double h)
- {
- return (h * h) * 6;
- }
- public static double sphereVolume(double r)
- {
- return ((r * r * r) * 3.14)/3;
- }
- public static double sphereSurface(double r)
- {
- return 4 * ((r * r) * 3.14);
- }
- public static double coneVolume(double h, double r)
- {
- return 3.14 * (r * r) * (h / 3);
- }
- public static double coneSurface(double h, double r)
- {
- return 3.14 * r * (r + r + h);
- }
- public static double cylinderVolume(double h, double r)
- {
- return 3.14 * (r * r) * h;
- }
- public static double cylinderSurface(double h, double r)
- {
- return 2 * (3.14 * (r * h)) + 2 * ((r * r)* 3.14);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement