Lab 1 Solution
Lab 1 Solution
package shape;
/**
*
* @author abdurrahmanjalil
*/
public abstract class Shape {
private int x;
private int y;
//constructor
public Shape( int x, int y){
this.x = x;
this.y = y;
}
//setX()
public void setX(int x){
this.x=x;
}
//setY()
public void setY(int y){
this.y=y;
}
//getX()
public int getX(){
return x;
}
//getY()
public int getY(){
return y;
}
package shape;
/**
*
* @author abdurrahmanjalil
*/
public abstract class TwoDimensionalShape extends Shape{
//constructor
public TwoDimensionalShape(int x, int y, int d1, int d2){
super(x,y);
dimension1 =d1;
dimension2 =d2;
2
}
//setDimension1
public void setD1(int d1){
this.dimension1=d1;
}
//setDimension2
public void setD2(int d2){
this.dimension2=d2;
}
//getDimension1
public int getD1(){
return dimension1;
}
//getDimension2
public int getD2(){
return dimension2;
}
//getArea()
public abstract int getArea();
package shape;
/**
*
* @author abdurrahmanjalil
3
*/
public class Circle extends TwoDimensionalShape {
//constructor
public Circle (int x, int y, int radius){
super(x, y, radius, radius);
//getName()
public String getName(){
return "Circle";
}
//getArea()
public int getArea(){
return (int)(Math.PI * getRadius() * getRadius());
//
public void setRadius(int radius){
setD1(radius);
setD2(radius);
}
4
}//end of class Circle
package shape;
/**
*
* @author abdurrahmanjalil
*/
public abstract class ThreeDimensionalShape extends Shape{
//constructor
public ThreeDimensionalShape(int x, int y, int d1, int d2, int d3){
super(x, y);
dimension1 =d1;
dimension2 =d2;
dimension3 =d2;
}
//setDimension1
public void setD1(int d1){
dimension1 = d1;
}
//setDimension2
public void setD2(int d2){
dimension2 = d2;
}
//setDimension3
5
public void setD3(int d3){
dimension3 = d3;
}
//getArea()
public abstract int getArea();
//getVolume()
public abstract int getVolume();
}
package shape;
/**
*
* @author abdurrahmanjalil
*/
public class Cube extends ThreeDimensionalShape {
6
public Cube(int x, int y, int d1, int d2, int d3){
super(x, y, d1, d2, d3);
}
return "Cube";
}
return getD1()*getD2()*6;
}
return getD1()*getD2()*getD3();
}