Advertisement
mmayoub

Circle.java

Jan 20th, 2023
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | Software | 0 0
  1. package proj20012023;
  2.  
  3. public class Circle {
  4.     // attributes
  5.     private double r;
  6.     private double x, y;
  7.  
  8.     // ctor
  9.     public Circle(double x, double y, double r) {
  10.         this.x = x;
  11.         this.y = y;
  12.         this.r = r;
  13.     }
  14.  
  15.     public Circle(double x, double y) {
  16.         this.x = x;
  17.         this.y = y;
  18.         this.r = 1.0;
  19.     }
  20.  
  21.     public Circle() {
  22.         this.x = 1;
  23.         this.y = 1;
  24.         this.r = 1;
  25.     }
  26.  
  27.     // getters
  28.     public double getR() {
  29.         return r;
  30.     }
  31.  
  32.     public double getX() {
  33.         return x;
  34.     }
  35.  
  36.     public double getY() {
  37.         return y;
  38.     }
  39.  
  40.     // setters
  41.     public void setR(double newR) {
  42.         if (newR >= 0)
  43.             r = newR;
  44.     }
  45.  
  46.     public void setX(double newX) {
  47.         x = newX;
  48.     }
  49.  
  50.     public void setY(double newY) {
  51.         y = newY;
  52.     }
  53.  
  54.     // get
  55.     public double getArea() {
  56.         double s = (Math.PI * r * r);
  57.         return s;
  58.     }
  59.  
  60.     // set
  61.     public void setArae(double area) {
  62.         if (area >= 0)
  63.             this.r = Math.sqrt(area / Math.PI);
  64.     }
  65.  
  66.     @Override
  67.     public String toString() {
  68.         return "Circle [r=" + r + ", x=" + x + ", y=" + y + "]";
  69.     }
  70.  
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement