write a java program that implements the following classes: A) a) Point in the Cartesian coordinate system. b) Circle with a given center and radius c) Cylinder with a given center, radius and heigth. d) Sphere with a given center and radius
The super class is the point class. circle is a subclass of the point class and cylinder and spere are subclasses of the circle class. All these classes should implements the following methods
1)getArea() method. 2)getVolume() method.
B)A class Called: RandomNumberGenerator that generate random numbers from 1 to 100
C)A class Test that tests the hierarchy in A) especiaaly the getArea() and getVolume() methods. Use an object from the Random NumberGenerator class to generate your input test data.
/**
* @author JavaWithUs
* www.javawithus.com
*/
class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
class Circle extends Point {
int radius;
public Circle(int x, int y, int radius) {
super(x, y);
this.radius = radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
}
class Cylinder extends Circle {
int height;
public Cylinder(int x, int y, int radius, int height) {
super(x, y, radius);
this.height = height;
}
public double getVolume() {
return getArea() * height;
}
@Override
public double getArea() {
return super.getArea() * 2 + (2 * Math.PI * radius * height);
}
}
class Sphere extends Circle {
int z;
public Sphere(int x, int y, int z, int radius) {
super(x, y, radius);
this.z = z;
}
@Override
public double getArea() {
return 4 * Math.PI * radius * radius;
}
public double getVolume() {
return 4 / 3 * Math.PI * Math.pow(radius, 3);
}
}