29 Aralık 2014 Pazartesi

Rectangle


public class Rectangle {

public double width,height;

//Representing of default values
public Rectangle()
{
width=1;
height=1;
}
//A new constructor for take datas in one line
public Rectangle(double width,double height){
this.width=width;
this.height=height;

}
//This is for taking width
public double getWidth(){
return width;
}
//This is for taking height
public double getHeight(){
return height;
}
//This provides to calculate area
public double getArea(){
return width*height;
}
//This provides to calculate perimeter
public double getPerimeter(){
return 2*(width+height);
}
//Output is shown to be string
public String toString(){
return " Rectangle.width="+this.width+" Rectangle.height="+this.height;
}

}

Hiç yorum yok:

Yorum Gönder