Object Classes
Can someone tell me why im getting an error for each of my other classes? The error is "The public type 'classname' must be defined in it's own file". How do I fix that? My friend said to put it in a package, but I don't know how.
publicclass Shapes{
publicstaticvoid main(String[] args){
Shape[] a =new Shape[5];
a[0] =new Rectangle(3, 4);
a[1] =new Square(5);
a[2] =new Circle(4);
a[3] =new Rectangle(5, 2);
a[4] =new Circle(5);
for (int i = 0; i != a.length; i++){
System.out.println(a[i]);
}
for (int i = 0; i != a.length; i++){
System.out.println(a[i].getArea());
}
for (int i = 0; i != a.length; i++){
a[i].move(2, 3);
}
for (int i = 0; i != a.length; i++){
System.out.println(a[i]);
}
((Rectangle)a[0]).exclusiveRectangleMethod();
((Rectangle)a[1]).exclusiveRectangleMethod();
}
}
publicclass Circleextends Shape{
publicint radius;
public Circle(int r){
radius = r;
}
publicint getArea(){
return (int)(Math.PI * radius * radius);
}
public String toString(){
return super.toString() +"; radius = " + radius;
}
}
abstractpublicclass Shape{
publicint x = 0;
publicint y = 0;
abstractpublicint getArea();
publicvoid move(int dx,int dy){
x += dx;
y += dy;
}
public String toString(){
return"x = " + x +"; y = " + y;
}
}
publicclass Rectangleextends Shape{
publicint height;
publicint width;
public Rectangle(int h,int w){
height = h;
width = w;
}
publicint getArea(){
return height * width;
}
public String toString(){
return"x = " + x +"; y = " + y
+"; height = " + height +"; width = " + width;
}
publicvoid exclusiveRectangleMethod(){
System.out.println("I'm a rectangle! I'm special!");
}
}
publicclass Squareextends Rectangle{
public Square(int x){
super(x, x);
}
}

