Question: To let this program work properly Do I need to compile and save each of these programs in a separate file with name on it

To let this program work properly Do I need to compile and save each of these programs in a separate file with name on it Like for java code "Figure"

for public class Rectangle "Rectangle"

circle, hexagon and Demo?

//Java Code

public abstract class Figure{ private int X, Y; // the center of the object. private String name; private static int numberOfShapes=0;

public Figure(){ X = 0; Y = 0; name = "none"; } public Figure(int a, int b, String n){ setX(a); setY(b); setName(n); numberOfShapes++; } public void setX(int a){X = a;} public void setY(int b){Y = b;} public void setName(String n){name = n;} public int getX(){return X;} public int getY(){return Y;} public String getName(){return name;} public static int getNumberOfShapes(){return numberOfShapes;} public abstract void erase(); public abstract void draw(); public void center(){ System.out.println(" In Figure. Centering at ("+getX()+","+getY()+")"); } }

//========================================

public class Rectangle extends Figure{ private int length; private int height;

public Rectangle() { super(0,0,"none"); setLength(0); setHeight(0); } public Rectangle(String n,int a, int b, int length, int height) { super(a, b, n); setLength(length); setHeight(height); } //setters

public void setLength(int length) { this.length = length; }

public void setHeight(int height) { this.height = height; } //getters

public int getLength() { return length; }

public int getHeight() { return height; }

@Override public void erase() { System.out.println("In Rectangle erasing"); }

@Override public void draw() { center(); erase(); System.out.println(""+this); } public String toString(){ return "In Rectangle Drawing "+getName()+" centered at ("+getX()+","+getY()+") height "+ getHeight()+" length "+getLength(); }

}

//================================================

public class Circle extends Figure { private int radius; public Circle() { super(0,0,"none"); setRadius(1); }

public Circle( String n,int a, int b, int radius) { super(a, b, n); setRadius(radius); }

public void setRadius(int radius) { this.radius = radius; }

public int getRadius() { return radius; } public String toString(){ return "In Circle Drawing "+getName()+" centered at ("+getX()+","+getY()+") radius "+getRadius(); } public void erase(){ System.out.println("In Circle erasing"); } public void draw(){ center(); erase(); System.out.println(""+this); } }

//============================================

public class Hexagon extends Figure{ int width, height; public Hexagon(){ super(0,0,"none"); setWidth(0); setHeight(0); } public Hexagon(String n, int a, int b, int w, int h){ super(a,b,n); setWidth(w); setHeight(h); } public String toString(){ return "In Hexagon Drawing "+getName()+" centered at ("+getX()+","+getY()+") width "+getWidth()+" height "+getHeight(); } public void erase(){ System.out.println("In Hexagon erasing"); } public void draw(){ center(); erase(); System.out.println(""+this); } public void setWidth(int w){width = w;} public void setHeight(int h){height = h;} public int getWidth(){return width;} public int getHeight(){return height;}

}

//=============================================

public class FigureDemo { public static void main(String[] args) { //Creating array of 100 figures Figure[] figures = new Figure[100];

//add figures figures[0] = new Rectangle("Rectangle",25,100,10,15); figures[1] = new Hexagon("Hexagon",22,45,10,50); figures[2] = new Circle("Circle",5,10,3); figures[3] = new Hexagon("Hexagon",33,14,100,50);

for(int i = 0; i < Figure.getNumberOfShapes(); i++){

figures[i].draw(); }

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!