class Fan(b) Define the Rectangle class that contains:
{
public static final int SLOW = 1;
public static final int MEDIUM = 2;
public static final int FAST = 3;
int speed;
boolean f_on;
double radius;
String color;
Fan()
{
speed = SLOW;
f_on = false;
radius = 4;
color = "blue";
}
Fan(int s,boolean f, double r, String c)
{
speed = s;
f_on = f;
radius = r;
color = c;
}
public void display()
{
if(f_on)
{
System.out.println("Speed of Fan : "+speed);
System.out.println("Radius of Fan : "+radius);
System.out.println("Color of Fan : "+color);
}
else
{
System.out.println("Fan is Off.");
System.out.println("Radius of Fan : "+radius);
System.out.println("Color of Fan : "+color);
}
}
}
class Q2bFanClassH2E
{
public static void main(String args[])
{
Fan f1 = new Fan();
f1.display();
Fan f2 = new Fan(2,true,6,"brown");
f2.display();
}
}
class Rectangle
{
double centerX,centerY,width,height;
double x1,x2,x3,x4,y1,y2,y3,y4;
Rectangle()
{
centerX=centerY=0;
width=height=1;
}
Rectangle(double x,double y,double w,double h)
{
centerX=x;
centerY=y;
width=w;
height=h;
}
double getArea()
{
return (width*height);
}
double getPerimeter()
{
return ( 2*(width+height) );
}
boolean contains(double x,double y)
{
x1=x3= ( centerX - (width/2) );
x2=x4= ( centerX + (width/2) );
y1=y2= (centerY + (height/2));
y3=y4= (centerY - (height/2));
if( (x > x1 && x < x4) && (y < y1 && y > y3))
return true;
else
return false;
}
}
class RectangleH2E
{
public static void main(String args[])
{
Rectangle r1Obj = new Rectangle();
Rectangle r2Obj = new Rectangle(200,200,100,50);
System.out.println("Rectangle 1 : Area "+r1Obj.getArea());
System.out.println("Rectangle 1 : Perimeter "+r1Obj.getPerimeter());
System.out.println("Rectangle 1 : Contains (3,2) "+r1Obj.contains(3,2));
System.out.println();
System.out.println("Rectangle 2 : Area "+r2Obj.getArea());
System.out.println("Rectangle 2 : Perimeter "+r2Obj.getPerimeter());
System.out.println("Rectangle 2 : Contains (160,190) "+r2Obj.contains(160,190));
}
}