Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rectangle {
- private double w;
- private double h;
- public Rectangle(double w, double h){
- this.w=w;
- this.h=h;
- }
- public Rectangle(Rectangle r){
- this.w=r.w;
- this.h=r.h;
- }
- public double perimeter(){
- return 2*h+2*w;
- }
- public double area(){
- return h*w;
- }
- public String toString() {
- return "Rectangle [w=" + w + ", h=" + h + "]";
- }
- public boolean contains(Point p){
- if (p.getX()<this.w && p.getY()<this.h)
- return true;
- else
- return false;
- }
- public int compare(Rectangle r){
- if (r.area()>this.area())
- return -1;
- else if(r.area()<this.area())
- return 1;
- else
- return 0;
- }
- public static void sort(Rectangle[] rectArr)
- {
- Rectangle temp;
- for (int i=0; i<rectArr.length; i++)
- {
- for (int j=0; j<(rectArr.length-i-1); j++)
- {
- if (rectArr[j].compare(rectArr[j+1])>0)
- {
- temp=rectArr[j];
- rectArr[j]=rectArr[j+1];
- rectArr[j+1]=temp;
- }
- }
- }
- System.out.print("your rectangle by increasing area are: ");
- for(int i=0; i<rectArr.length; i++)
- System.out.print(rectArr[i]+" ");
- }
- /*public Point maxIn(Rectangle[] arr){
- int counter=0;
- Rectangle []arr1= new Rectangle[5];
- arr1[0]=new Rectangle(5,5);
- arr1[1]=new Rectangle(1, 3);
- arr1[2]=new Rectangle(7, 2);
- arr1[3]=new Rectangle(1.7, 7.8);
- arr1[4]=new Rectangle(2.4, 4.6);
- if (p.contains(arr[0]))
- counter++;
- return ;*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement