Advertisement
daniv1

Untitled

May 4th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.  
  2. import java.awt.Graphics;
  3.  
  4. public class Square{
  5.  
  6.   public int x;
  7.   public int y;
  8.   public int a;
  9.   public int b;
  10.  
  11. public Square() {
  12.   x=70;
  13.   y=150;
  14.   a=20;
  15.   b = 30;
  16. }
  17. public Square(int x, int y, int a , int b){
  18.   this.x=x;
  19.   this.y=y;
  20.   this.a=a;
  21.   this.b = b;
  22. }
  23. public void drawSquare(Graphics g) {
  24.   g.drawRect(x, y, a, b);
  25. }
  26. public void isSquare() {
  27.     if(a == b)
  28.         System.out.println("Квадрат");
  29.     else
  30.         System.out.println("Прямокутник");
  31. }
  32. public int CalculateArea() {
  33.     return a*b;
  34. }
  35.  
  36. public void CheckArea(Square ob) {
  37.     if(CalculateArea() > ob.CalculateArea()) {
  38.         System.out.println("Площа 1 більша");
  39.     }
  40.     else
  41.         System.out.println("Площа 2 більша");
  42. }
  43. public double getLenght(Square ob) {
  44.     return Math.sqrt((ob.x + ob.a/2 - x - a/2)*(ob.x + ob.a/2 - x - a/2)  + (ob.y + ob.b/2 - y - b/2)*(ob.y + ob.b/2 - y - b/2));
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement