aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java/lab6/Polygon.java
blob: 643dbb365940ada74911fa6a51d0c5877e233534 (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
class Polygon 
{ 
  private int[] sideLengths; 
 
  public Polygon(int sides, int ... lengths) 
  { 
    int index = 0; 
    sideLengths = new int[sides]; 
    for (int length: lengths) 
    { 
      sideLengths[index] = length; 
      index += 1; 
    } 
  } 
     
  public int side(int number) 
  { 
    return sideLengths[number]; 
  } 
     
  public int perimeter() 
  { 
    int total = 0; 
    for (int index = 0; index < sideLengths.length; index += 1) 
    { 
      total += side(index); 
    } 
    return total; 
  } 
}