summaryrefslogtreecommitdiffstats
path: root/Java/Square/Square.java
blob: 4ea72e9277cf7881d347dbe97164c42e8d6e4842 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public class Square {

  // data member
  private double length;


  
  // Constructors
  //accepts r as length
  public Square (double l) {
    length = l;
  }
//no r? assume length is 1
  public Square() {
    length = 1;
  }
//copy's length from another circle
  public Square (Square s) {
    length = s.length;
  }

  // setter & getter
  // sets length
  public void setLength(double l) {
    length = l;
  }
//return length
  public double getLength() {
    return length;
  }

  // other methods
  public double area() {
    return Math.pow(length,2);
  }

  public double perimeter() {
    return length*4;
  }

}