diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2019-10-16 14:56:08 -0500 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2019-10-16 14:56:08 -0500 |
commit | 4e15412bd6bbc53bf60dadd1587fff93de2c83b7 (patch) | |
tree | 88e79634f953e9cb62c81599bc646e35abe7435f /csci1913/Java/lab6/Polygon.java | |
parent | Move things around (diff) | |
download | homework-4e15412bd6bbc53bf60dadd1587fff93de2c83b7.tar homework-4e15412bd6bbc53bf60dadd1587fff93de2c83b7.tar.gz homework-4e15412bd6bbc53bf60dadd1587fff93de2c83b7.tar.bz2 homework-4e15412bd6bbc53bf60dadd1587fff93de2c83b7.tar.lz homework-4e15412bd6bbc53bf60dadd1587fff93de2c83b7.tar.xz homework-4e15412bd6bbc53bf60dadd1587fff93de2c83b7.tar.zst homework-4e15412bd6bbc53bf60dadd1587fff93de2c83b7.zip |
Finish lab
Diffstat (limited to '')
-rw-r--r-- | csci1913/Java/lab6/Polygon.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/csci1913/Java/lab6/Polygon.java b/csci1913/Java/lab6/Polygon.java new file mode 100644 index 0000000..7f025fe --- /dev/null +++ b/csci1913/Java/lab6/Polygon.java @@ -0,0 +1,32 @@ +package lab6; + +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; + } +} |