import java.util.*;
class Line extends Shape {
private Point start, end;
private double width;
protected String name;
Line(String name, Point x, Point y, double w)
{
this.name = name;
start = x;
end = y;
width = w;
}
public String toString() {
return name + " starts at " + start + " to " + end + " of width = " + width;
}
}
class fancyLine extends Line{
private String drawType;
fancyLine(String n, Point a, Point b, double w, String type)
{
super(n,a,b,w);
drawType = type;
}
public String toString()
{
return super.toString() + " and is a " + drawType;
}
}
class Point extends Shape{ //possibly extends line
public int x, y, z;
Point(int x, int y) {
this.x = x;
this.y = y;
}
Point(Point p) {
this(p.x, p.y);
}
Point(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
public String toString()
{
return "(" + x + "," + y +")";
}
}
class Circle extends Shape{ //possibly extend line
protected double radius;
protected double center;
protected double name;
protected double area;
Circle(String name, Point p, double r) {
center = p;
radius = r;
area = (3.14 * (radius * radius));
this.name = name;
}
Circle(String n, Circle x) {
this.center = center;
this.radius = radius;
area = (3.14 * (radius * radius));
n = name;
}
public double getArea()
{
return Math.PI * Math.pow(radius, 2);
}
public String toString()
{
return name + " originates at " + center + " extends for a radius of " + radius + "the original circles has an area of " + area;
}
}
class Cylinder extends Circle{
private int height;
private Point cylCenter;
private double cylRadius;
Cylinder(String n, Point x, double r, int h){
super(n, x, r);
height = h;
cylCenter = x;
cylRadius = r;
name = n;
}
Cylinder(String n, Circle x, int h){
super(n, x, r);
height = h;
cylCenter = x;
cylRadius = r;
name = n;
}
public String toString()
{
return name + " originates at " + cylCenter + " with a radius of " + cylRadius + " with a height of " + height;
}
}
class Rectangle extends Shape {
protected Point one, two, three, four;
protected int height;
protected String name;
Rectangle(String n, Point start, Point width, Point top){
name = n;
one = start;
two = width;
three = top;
height = getValy(three) - getValy(one);
}
int getValx (Point x) {
return x.x;
}
int getValy (Point y) {
return y.y;
}
public String toString()
{
return name + " originates at " + one + " its second point is " + two + " and has a height of " + height;
}
}
class Cube extends Rectangle {
private int depth;
Cube(String n, Point start, Point width, Point top, int depth) {
super(n, start, width, top);
this.depth = depth;
}
}
abstract class Shape {
static ArrayList<Shape> container = new ArrayList<Shape>();
public static void main(String args[]) {
//define the points
Point origin = new Point (0,0);
Point twoTwo = new Point (2,2);
Point twoZero = new Point (2,0);
Point fourFour = new Point (4,4);
Point fiveFive = new Point (5,5);
Point sixSix = new Point (6,6);
Point eightEight = new Point (8,8);
Point zeroZeroFive = new Point (0,0,5);
Line lineOne = new Line("Line One", origin, twoTwo, 2.1);
container.add(lineOne); //line
Line lineTwo = new fancyLine("Line Two", origin, twoTwo, 2.1, "Fancy");
container.add(lineTwo); //fancy line
Circle circleOne = new Circle("Circle One", twoTwo, 3.1);
container.add(circleOne); //circle
Cylinder cylOne = new Cylinder("Cylinder One", circleOne, 5);
container.add(cylOne); //cylinder
Cylinder cylTwo = new Cylinder("Cylinder Two", twoTwo, 3.1, 5);
container.add(cylTwo); //cylinder method two
Rectangle recOne = new Rectangle("Rectangle One", origin, twoZero, twoTwo);
container.add(recOne); //rectangle
Cube cubeOne = new Cube("Cube One", origin, twoZero, twoTwo, 2);
container.add(cubeOne); //cube
for (Shape a : container)
System.out.println(a + " ");
}
}