From 4e15412bd6bbc53bf60dadd1587fff93de2c83b7 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Wed, 16 Oct 2019 14:56:08 -0500 Subject: Finish lab --- csci1913/Java/lab6/Polygon.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 csci1913/Java/lab6/Polygon.java (limited to 'csci1913/Java/lab6/Polygon.java') 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; + } +} -- cgit v1.2.3