SlideShare a Scribd company logo
Polygon.java
public class Polygon {
private int numSides;
private double sideLength;
private double xCoord;
private double yCoord;
private double apothem;
private double perimeter;
private double area;
//Constructor
public Polygon (double xCentCoord, double yCentCoord, int countSides, double measLength,
double measApothem, double measPerimeter) {
xCoord = xCentCoord;
yCoord = yCentCoord;
numSides = countSides;
sideLength = measLength;
apothem = measApothem;
perimeter = measPerimeter;
}
//No argument constructor
public Polygon () {
xCoord = 0.0;
yCoord = 0.0;
numSides = 4;
sideLength = 10.0;
apothem = 5.0;
perimeter = 20.0;
}
//Setter Methods
//setX()
public void setXCoord(double xCentCoord) {
xCoord = xCentCoord;
}
//setY()
public void setYCoord(double yCentCoord) {
yCoord = yCentCoord;
}
//setNumSides()
public void setNumSides(int countSides) {
numSides = countSides;
}
//setSideLength()
public void setSideLength(double measLength) {
sideLength = measLength;
}
//setApothem()
public void setApothem(double measApothem) {
apothem = measApothem;
}
//Getter methods
//getXCoord
public double getXCoord() {
return xCoord;
}
//getYCoord
public double getYCoord() {
return yCoord;
}
//getNumSides
public int getNumSides() {
return numSides;
}
//getSideLength()
public double getSideLength() {
return sideLength;
}
//getApothem()
public double getApothem() {
return apothem;
}
//getPerimeter()
public double getPerimeter() {
return perimeter;
}
//getArea()
public double getArea() {
return area;
}
//Calculate for perimeter
public double getPerimeter(Polygon multiple){
double perimeter = multiple.getNumSides() * multiple.getSideLength();
return perimeter;
}
//Calculate for area
public double getArea(Polygon multiple) {
double area = 0.5 * multiple.getApothem() * multiple.getPerimeter();
return area;
}
//toString method
public String toString() {
String str = "numsides= " + numSides + ", sideLength= " + sideLength;
return str;
}
}
TestPolygon.java
//import Scanner
import java.util.Scanner;
public class TestPolygon {
public static void main(String[] args) {
//Construct a point with x = 1.0, y = 1.0
Polygon multiple = new Polygon();
//Display the values using toString
System.out.println("toString() results: " + multiple.toString());
//Call the getter methods
double xCoord2 = multiple.getXCoord();
double yCoord2 = multiple.getYCoord();
int numSides2 = multiple.getNumSides();
double sideLength2 = multiple.getSideLength();
double apothem2 = multiple.getApothem();
double perimeter2 = multiple.getPerimeter();
double area2 = multiple.getArea();
//Print results
System.out.println("xCoord= " + xCoord2 + ", yCoord= " + yCoord2 + ", apothem= "
+apothem2);
System.out.println("getNumsides() results: " + numSides2);
System.out.println("getSideLength() results: " + sideLength2);
System.out.println("getXCoord() results: " + xCoord2);
System.out.println("getYCoord() results: " + yCoord2);
System.out.println("getApothem() results: " + apothem2);
System.out.println("getPerimeter() results: " +perimeter2);
System.out.println("getArea() results: " + area2);
//Setter methods for numSides
int newNumSides = 4;
multiple.setNumSides(newNumSides);
//Print newNumSides
System.out.println("setNumSides(4) results: " + newNumSides);
//Setter methods for sideLength
double newSideLength = 3;
multiple.setSideLength(newSideLength);
//Print newSideLength
System.out.println("setSideLength(3) results: " + newSideLength);
//Setter methods for xCoord
double newXCoord = 2.0;
multiple.setXCoord(newXCoord);
//Print newXCoord
System.out.println("setXCoord(2.0) results: " + newXCoord);
//Setter methods for yCoord
double newYCoord = 2.0;
multiple.setYCoord(newYCoord);
//Print newXCoord
System.out.println("setYCoord(2.0) results: " + newYCoord);
//Setter methods for apothem
double newApothem = 2.0;
multiple.setApothem(newApothem);
//Print newApothem
System.out.println("setApothem(2.0) results: " + newApothem);
Scanner scannerIn=new Scanner(System.in);
//Set up to create 5 different polygons with new inputs by user
//Repeat 5 times with for loop
int userNumSides = 0;
double userSideLength = 0.0;
double userXCoord = 0.0;
double userYCoord = 0.0;
double userApothem = 0.0;
//input the x & y coordinate, numSide, sideLength, and apothem
for (int i = 0; i<5; i++) {
System.out.print("Enter the number of polygon sides (ex 5): ");
userNumSides = scannerIn.nextInt();
System.out.print("Enter the length of the polygon sides (ex 6.8): ");
userSideLength = scannerIn.nextDouble();
System.out.print("Enter the x coordinate (ex 1.2): ");
userXCoord = scannerIn.nextDouble();
System.out.print("Enter the y coordinate (ex 3.4): ");
userYCoord = scannerIn.nextDouble();
System.out.print("Enter the length of apothem (ex 0.8): ");
userApothem = scannerIn.nextDouble();
double userPerimeter = userNumSides * userSideLength;
double userArea = 0.5 * userApothem * userPerimeter;
//print results
System.out.print("userNumSides() results: " + userNumSides);
System.out.print("userSideLength() results: " + userSideLength);
System.out.print("userXCoord() results: " + userXCoord);
System.out.print("userYCoord() results: " + userYCoord);
System.out.print("userApothem() results: " + userApothem);
System.out.print("Perimeter of polygon is: " + userPerimeter);
System.out.print("Area of polygon is: " + userArea);
System.out.println("setNumSides(4) results: " + newNumSides);
System.out.println("setSideLength(3) results: " + newSideLength);
System.out.println("setXCoord(2.0) results: " + newXCoord);
System.out.println("setYCoord(2.0) results: " + newYCoord);
System.out.println("setApothem(2.0) results: " + newApothem);
}
}
}
Output:
toString() results: numsides= 4, sideLength= 10.0
xCoord= 0.0, yCoord= 0.0, apothem= 5.0
getNumsides() results: 4
getSideLength() results: 10.0
getXCoord() results: 0.0
getYCoord() results: 0.0
getApothem() results: 5.0
getPerimeter() results: 20.0
getArea() results: 0.0
setNumSides(4) results: 4
setSideLength(3) results: 3.0
setXCoord(2.0) results: 2.0
setYCoord(2.0) results: 2.0
setApothem(2.0) results: 2.0
Enter the number of polygon sides (ex 5): 3
Enter the length of the polygon sides (ex 6.8): 4
Enter the x coordinate (ex 1.2): 1.2
Enter the y coordinate (ex 3.4): 3.4
Enter the length of apothem (ex 0.8): 0.5
userNumSides() results: 3userSideLength() results: 4.0userXCoord() results: 1.2userYCoord()
results: 3.4userApothem() results: 0.5Perimeter of polygon is: 12.0Area of polygon is:
3.0setNumSides(4) results: 4
setSideLength(3) results: 3.0
setXCoord(2.0) results: 2.0
setYCoord(2.0) results: 2.0
setApothem(2.0) results: 2.0
Enter the number of polygon sides (ex 5):
Solution
Polygon.java
public class Polygon {
private int numSides;
private double sideLength;
private double xCoord;
private double yCoord;
private double apothem;
private double perimeter;
private double area;
//Constructor
public Polygon (double xCentCoord, double yCentCoord, int countSides, double measLength,
double measApothem, double measPerimeter) {
xCoord = xCentCoord;
yCoord = yCentCoord;
numSides = countSides;
sideLength = measLength;
apothem = measApothem;
perimeter = measPerimeter;
}
//No argument constructor
public Polygon () {
xCoord = 0.0;
yCoord = 0.0;
numSides = 4;
sideLength = 10.0;
apothem = 5.0;
perimeter = 20.0;
}
//Setter Methods
//setX()
public void setXCoord(double xCentCoord) {
xCoord = xCentCoord;
}
//setY()
public void setYCoord(double yCentCoord) {
yCoord = yCentCoord;
}
//setNumSides()
public void setNumSides(int countSides) {
numSides = countSides;
}
//setSideLength()
public void setSideLength(double measLength) {
sideLength = measLength;
}
//setApothem()
public void setApothem(double measApothem) {
apothem = measApothem;
}
//Getter methods
//getXCoord
public double getXCoord() {
return xCoord;
}
//getYCoord
public double getYCoord() {
return yCoord;
}
//getNumSides
public int getNumSides() {
return numSides;
}
//getSideLength()
public double getSideLength() {
return sideLength;
}
//getApothem()
public double getApothem() {
return apothem;
}
//getPerimeter()
public double getPerimeter() {
return perimeter;
}
//getArea()
public double getArea() {
return area;
}
//Calculate for perimeter
public double getPerimeter(Polygon multiple){
double perimeter = multiple.getNumSides() * multiple.getSideLength();
return perimeter;
}
//Calculate for area
public double getArea(Polygon multiple) {
double area = 0.5 * multiple.getApothem() * multiple.getPerimeter();
return area;
}
//toString method
public String toString() {
String str = "numsides= " + numSides + ", sideLength= " + sideLength;
return str;
}
}
TestPolygon.java
//import Scanner
import java.util.Scanner;
public class TestPolygon {
public static void main(String[] args) {
//Construct a point with x = 1.0, y = 1.0
Polygon multiple = new Polygon();
//Display the values using toString
System.out.println("toString() results: " + multiple.toString());
//Call the getter methods
double xCoord2 = multiple.getXCoord();
double yCoord2 = multiple.getYCoord();
int numSides2 = multiple.getNumSides();
double sideLength2 = multiple.getSideLength();
double apothem2 = multiple.getApothem();
double perimeter2 = multiple.getPerimeter();
double area2 = multiple.getArea();
//Print results
System.out.println("xCoord= " + xCoord2 + ", yCoord= " + yCoord2 + ", apothem= "
+apothem2);
System.out.println("getNumsides() results: " + numSides2);
System.out.println("getSideLength() results: " + sideLength2);
System.out.println("getXCoord() results: " + xCoord2);
System.out.println("getYCoord() results: " + yCoord2);
System.out.println("getApothem() results: " + apothem2);
System.out.println("getPerimeter() results: " +perimeter2);
System.out.println("getArea() results: " + area2);
//Setter methods for numSides
int newNumSides = 4;
multiple.setNumSides(newNumSides);
//Print newNumSides
System.out.println("setNumSides(4) results: " + newNumSides);
//Setter methods for sideLength
double newSideLength = 3;
multiple.setSideLength(newSideLength);
//Print newSideLength
System.out.println("setSideLength(3) results: " + newSideLength);
//Setter methods for xCoord
double newXCoord = 2.0;
multiple.setXCoord(newXCoord);
//Print newXCoord
System.out.println("setXCoord(2.0) results: " + newXCoord);
//Setter methods for yCoord
double newYCoord = 2.0;
multiple.setYCoord(newYCoord);
//Print newXCoord
System.out.println("setYCoord(2.0) results: " + newYCoord);
//Setter methods for apothem
double newApothem = 2.0;
multiple.setApothem(newApothem);
//Print newApothem
System.out.println("setApothem(2.0) results: " + newApothem);
Scanner scannerIn=new Scanner(System.in);
//Set up to create 5 different polygons with new inputs by user
//Repeat 5 times with for loop
int userNumSides = 0;
double userSideLength = 0.0;
double userXCoord = 0.0;
double userYCoord = 0.0;
double userApothem = 0.0;
//input the x & y coordinate, numSide, sideLength, and apothem
for (int i = 0; i<5; i++) {
System.out.print("Enter the number of polygon sides (ex 5): ");
userNumSides = scannerIn.nextInt();
System.out.print("Enter the length of the polygon sides (ex 6.8): ");
userSideLength = scannerIn.nextDouble();
System.out.print("Enter the x coordinate (ex 1.2): ");
userXCoord = scannerIn.nextDouble();
System.out.print("Enter the y coordinate (ex 3.4): ");
userYCoord = scannerIn.nextDouble();
System.out.print("Enter the length of apothem (ex 0.8): ");
userApothem = scannerIn.nextDouble();
double userPerimeter = userNumSides * userSideLength;
double userArea = 0.5 * userApothem * userPerimeter;
//print results
System.out.print("userNumSides() results: " + userNumSides);
System.out.print("userSideLength() results: " + userSideLength);
System.out.print("userXCoord() results: " + userXCoord);
System.out.print("userYCoord() results: " + userYCoord);
System.out.print("userApothem() results: " + userApothem);
System.out.print("Perimeter of polygon is: " + userPerimeter);
System.out.print("Area of polygon is: " + userArea);
System.out.println("setNumSides(4) results: " + newNumSides);
System.out.println("setSideLength(3) results: " + newSideLength);
System.out.println("setXCoord(2.0) results: " + newXCoord);
System.out.println("setYCoord(2.0) results: " + newYCoord);
System.out.println("setApothem(2.0) results: " + newApothem);
}
}
}
Output:
toString() results: numsides= 4, sideLength= 10.0
xCoord= 0.0, yCoord= 0.0, apothem= 5.0
getNumsides() results: 4
getSideLength() results: 10.0
getXCoord() results: 0.0
getYCoord() results: 0.0
getApothem() results: 5.0
getPerimeter() results: 20.0
getArea() results: 0.0
setNumSides(4) results: 4
setSideLength(3) results: 3.0
setXCoord(2.0) results: 2.0
setYCoord(2.0) results: 2.0
setApothem(2.0) results: 2.0
Enter the number of polygon sides (ex 5): 3
Enter the length of the polygon sides (ex 6.8): 4
Enter the x coordinate (ex 1.2): 1.2
Enter the y coordinate (ex 3.4): 3.4
Enter the length of apothem (ex 0.8): 0.5
userNumSides() results: 3userSideLength() results: 4.0userXCoord() results: 1.2userYCoord()
results: 3.4userApothem() results: 0.5Perimeter of polygon is: 12.0Area of polygon is:
3.0setNumSides(4) results: 4
setSideLength(3) results: 3.0
setXCoord(2.0) results: 2.0
setYCoord(2.0) results: 2.0
setApothem(2.0) results: 2.0
Enter the number of polygon sides (ex 5):

More Related Content

Similar to Polygon.javapublic class Polygon { private int numSides; priva.pdf

need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
arcotstarsports
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
arcotstarsports
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
Peter Gfader
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
Peter Gfader
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
ssuser562afc1
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
ssuser562afc1
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
ANJALIENTERPRISES1
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
ANJALIENTERPRISES1
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
varadasuren
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
varadasuren
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
Akira Maruoka
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
Akira Maruoka
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
rajkumari873
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
rajkumari873
 
I worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdfI worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdf
sudhinjv
 
I worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdfI worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdf
sudhinjv
 

Similar to Polygon.javapublic class Polygon { private int numSides; priva.pdf (20)

need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
 
Ac2
Ac2Ac2
Ac2
 
Ac2
Ac2Ac2
Ac2
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
I worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdfI worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdf
 
I worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdfI worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdf
 

More from apnafreez

Cu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdf
Cu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdfCu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdf
Cu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdf
apnafreez
 
C) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdf
C) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdfC) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdf
C) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdf
apnafreez
 
Before getting public issues he should consider are 1. Increase i.pdf
Before getting public issues he should consider are 1. Increase i.pdfBefore getting public issues he should consider are 1. Increase i.pdf
Before getting public issues he should consider are 1. Increase i.pdf
apnafreez
 
Assets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdf
Assets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdfAssets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdf
Assets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdf
apnafreez
 
1)Interest per year 8106= 135Simple interest = Amount RateTime.pdf
1)Interest per year 8106= 135Simple interest = Amount  RateTime.pdf1)Interest per year 8106= 135Simple interest = Amount  RateTime.pdf
1)Interest per year 8106= 135Simple interest = Amount RateTime.pdf
apnafreez
 
AnswerAnswer1. The body of a fungus is in the form of solid sh.pdf
AnswerAnswer1. The body of a fungus is in the form of solid sh.pdfAnswerAnswer1. The body of a fungus is in the form of solid sh.pdf
AnswerAnswer1. The body of a fungus is in the form of solid sh.pdf
apnafreez
 
A. This constitutes part of a gene that encodes information for RNA .pdf
A. This constitutes part of a gene that encodes information for RNA .pdfA. This constitutes part of a gene that encodes information for RNA .pdf
A. This constitutes part of a gene that encodes information for RNA .pdf
apnafreez
 
A. ANSAutosomal dominant (a trait could passed down from previous.pdf
A. ANSAutosomal dominant (a trait could passed down from previous.pdfA. ANSAutosomal dominant (a trait could passed down from previous.pdf
A. ANSAutosomal dominant (a trait could passed down from previous.pdf
apnafreez
 
888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf
apnafreez
 
18) One device is attached to a physical interface    The switch c.pdf
18) One device is attached to a physical interface    The switch c.pdf18) One device is attached to a physical interface    The switch c.pdf
18) One device is attached to a physical interface    The switch c.pdf
apnafreez
 
1.Joseph could not restrain himself before all those who stood by hi.pdf
1.Joseph could not restrain himself before all those who stood by hi.pdf1.Joseph could not restrain himself before all those who stood by hi.pdf
1.Joseph could not restrain himself before all those who stood by hi.pdf
apnafreez
 
(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf
(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf
(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf
apnafreez
 
Nursing is a healthcare profession in which they serve the patients .pdf
  Nursing is a healthcare profession in which they serve the patients .pdf  Nursing is a healthcare profession in which they serve the patients .pdf
Nursing is a healthcare profession in which they serve the patients .pdf
apnafreez
 
yes.because the deposted money can be multiply with 10 and it beco.pdf
yes.because the deposted money can be multiply with 10 and it beco.pdfyes.because the deposted money can be multiply with 10 and it beco.pdf
yes.because the deposted money can be multiply with 10 and it beco.pdf
apnafreez
 
When the substituent groups are oriented in the s.pdf
                     When the substituent groups are oriented in the s.pdf                     When the substituent groups are oriented in the s.pdf
When the substituent groups are oriented in the s.pdf
apnafreez
 
using System;public category take a look at one.00m; Console.W.pdf
using System;public category take a look at one.00m; Console.W.pdfusing System;public category take a look at one.00m; Console.W.pdf
using System;public category take a look at one.00m; Console.W.pdf
apnafreez
 
Tunnel through the IPv4--Internet traffic is expected to be carr.pdf
Tunnel through the IPv4--Internet traffic is expected to be carr.pdfTunnel through the IPv4--Internet traffic is expected to be carr.pdf
Tunnel through the IPv4--Internet traffic is expected to be carr.pdf
apnafreez
 
The sum is 250.SolutionThe sum is 250..pdf
The sum is 250.SolutionThe sum is 250..pdfThe sum is 250.SolutionThe sum is 250..pdf
The sum is 250.SolutionThe sum is 250..pdf
apnafreez
 
The  key activity areas for securities firms are i. Investing Se.pdf
The  key activity areas for securities firms are i. Investing Se.pdfThe  key activity areas for securities firms are i. Investing Se.pdf
The  key activity areas for securities firms are i. Investing Se.pdf
apnafreez
 
The finger like projections of intestine known as villi increases su.pdf
The finger like projections of intestine known as villi increases su.pdfThe finger like projections of intestine known as villi increases su.pdf
The finger like projections of intestine known as villi increases su.pdf
apnafreez
 

More from apnafreez (20)

Cu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdf
Cu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdfCu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdf
Cu(H2O)42+(aq) + 4CN-(aq) = Cu(CN)42-(aq) +4 H2O(l)Cu+2 is a Lew.pdf
 
C) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdf
C) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdfC) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdf
C) CS2 for sureA, B, D and E are all ionic compoundsSolution.pdf
 
Before getting public issues he should consider are 1. Increase i.pdf
Before getting public issues he should consider are 1. Increase i.pdfBefore getting public issues he should consider are 1. Increase i.pdf
Before getting public issues he should consider are 1. Increase i.pdf
 
Assets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdf
Assets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdfAssets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdf
Assets=Liabilities+Stockholders EquityCash given $1000 on the sa.pdf
 
1)Interest per year 8106= 135Simple interest = Amount RateTime.pdf
1)Interest per year 8106= 135Simple interest = Amount  RateTime.pdf1)Interest per year 8106= 135Simple interest = Amount  RateTime.pdf
1)Interest per year 8106= 135Simple interest = Amount RateTime.pdf
 
AnswerAnswer1. The body of a fungus is in the form of solid sh.pdf
AnswerAnswer1. The body of a fungus is in the form of solid sh.pdfAnswerAnswer1. The body of a fungus is in the form of solid sh.pdf
AnswerAnswer1. The body of a fungus is in the form of solid sh.pdf
 
A. This constitutes part of a gene that encodes information for RNA .pdf
A. This constitutes part of a gene that encodes information for RNA .pdfA. This constitutes part of a gene that encodes information for RNA .pdf
A. This constitutes part of a gene that encodes information for RNA .pdf
 
A. ANSAutosomal dominant (a trait could passed down from previous.pdf
A. ANSAutosomal dominant (a trait could passed down from previous.pdfA. ANSAutosomal dominant (a trait could passed down from previous.pdf
A. ANSAutosomal dominant (a trait could passed down from previous.pdf
 
888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf
 
18) One device is attached to a physical interface    The switch c.pdf
18) One device is attached to a physical interface    The switch c.pdf18) One device is attached to a physical interface    The switch c.pdf
18) One device is attached to a physical interface    The switch c.pdf
 
1.Joseph could not restrain himself before all those who stood by hi.pdf
1.Joseph could not restrain himself before all those who stood by hi.pdf1.Joseph could not restrain himself before all those who stood by hi.pdf
1.Joseph could not restrain himself before all those who stood by hi.pdf
 
(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf
(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf
(a) Total amount of I2 = 501000 x 0.010 = 0.0005 mol = 0.5 mmolLe.pdf
 
Nursing is a healthcare profession in which they serve the patients .pdf
  Nursing is a healthcare profession in which they serve the patients .pdf  Nursing is a healthcare profession in which they serve the patients .pdf
Nursing is a healthcare profession in which they serve the patients .pdf
 
yes.because the deposted money can be multiply with 10 and it beco.pdf
yes.because the deposted money can be multiply with 10 and it beco.pdfyes.because the deposted money can be multiply with 10 and it beco.pdf
yes.because the deposted money can be multiply with 10 and it beco.pdf
 
When the substituent groups are oriented in the s.pdf
                     When the substituent groups are oriented in the s.pdf                     When the substituent groups are oriented in the s.pdf
When the substituent groups are oriented in the s.pdf
 
using System;public category take a look at one.00m; Console.W.pdf
using System;public category take a look at one.00m; Console.W.pdfusing System;public category take a look at one.00m; Console.W.pdf
using System;public category take a look at one.00m; Console.W.pdf
 
Tunnel through the IPv4--Internet traffic is expected to be carr.pdf
Tunnel through the IPv4--Internet traffic is expected to be carr.pdfTunnel through the IPv4--Internet traffic is expected to be carr.pdf
Tunnel through the IPv4--Internet traffic is expected to be carr.pdf
 
The sum is 250.SolutionThe sum is 250..pdf
The sum is 250.SolutionThe sum is 250..pdfThe sum is 250.SolutionThe sum is 250..pdf
The sum is 250.SolutionThe sum is 250..pdf
 
The  key activity areas for securities firms are i. Investing Se.pdf
The  key activity areas for securities firms are i. Investing Se.pdfThe  key activity areas for securities firms are i. Investing Se.pdf
The  key activity areas for securities firms are i. Investing Se.pdf
 
The finger like projections of intestine known as villi increases su.pdf
The finger like projections of intestine known as villi increases su.pdfThe finger like projections of intestine known as villi increases su.pdf
The finger like projections of intestine known as villi increases su.pdf
 

Recently uploaded

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Polygon.javapublic class Polygon { private int numSides; priva.pdf

  • 1. Polygon.java public class Polygon { private int numSides; private double sideLength; private double xCoord; private double yCoord; private double apothem; private double perimeter; private double area; //Constructor public Polygon (double xCentCoord, double yCentCoord, int countSides, double measLength, double measApothem, double measPerimeter) { xCoord = xCentCoord; yCoord = yCentCoord; numSides = countSides; sideLength = measLength; apothem = measApothem; perimeter = measPerimeter; } //No argument constructor public Polygon () { xCoord = 0.0; yCoord = 0.0; numSides = 4; sideLength = 10.0; apothem = 5.0; perimeter = 20.0; } //Setter Methods //setX() public void setXCoord(double xCentCoord) { xCoord = xCentCoord; } //setY() public void setYCoord(double yCentCoord) {
  • 2. yCoord = yCentCoord; } //setNumSides() public void setNumSides(int countSides) { numSides = countSides; } //setSideLength() public void setSideLength(double measLength) { sideLength = measLength; } //setApothem() public void setApothem(double measApothem) { apothem = measApothem; } //Getter methods //getXCoord public double getXCoord() { return xCoord; } //getYCoord public double getYCoord() { return yCoord; } //getNumSides public int getNumSides() { return numSides; } //getSideLength() public double getSideLength() { return sideLength; } //getApothem() public double getApothem() { return apothem; }
  • 3. //getPerimeter() public double getPerimeter() { return perimeter; } //getArea() public double getArea() { return area; } //Calculate for perimeter public double getPerimeter(Polygon multiple){ double perimeter = multiple.getNumSides() * multiple.getSideLength(); return perimeter; } //Calculate for area public double getArea(Polygon multiple) { double area = 0.5 * multiple.getApothem() * multiple.getPerimeter(); return area; } //toString method public String toString() { String str = "numsides= " + numSides + ", sideLength= " + sideLength; return str; } } TestPolygon.java //import Scanner import java.util.Scanner; public class TestPolygon { public static void main(String[] args) { //Construct a point with x = 1.0, y = 1.0 Polygon multiple = new Polygon(); //Display the values using toString System.out.println("toString() results: " + multiple.toString());
  • 4. //Call the getter methods double xCoord2 = multiple.getXCoord(); double yCoord2 = multiple.getYCoord(); int numSides2 = multiple.getNumSides(); double sideLength2 = multiple.getSideLength(); double apothem2 = multiple.getApothem(); double perimeter2 = multiple.getPerimeter(); double area2 = multiple.getArea(); //Print results System.out.println("xCoord= " + xCoord2 + ", yCoord= " + yCoord2 + ", apothem= " +apothem2); System.out.println("getNumsides() results: " + numSides2); System.out.println("getSideLength() results: " + sideLength2); System.out.println("getXCoord() results: " + xCoord2); System.out.println("getYCoord() results: " + yCoord2); System.out.println("getApothem() results: " + apothem2); System.out.println("getPerimeter() results: " +perimeter2); System.out.println("getArea() results: " + area2); //Setter methods for numSides int newNumSides = 4; multiple.setNumSides(newNumSides); //Print newNumSides System.out.println("setNumSides(4) results: " + newNumSides); //Setter methods for sideLength double newSideLength = 3; multiple.setSideLength(newSideLength); //Print newSideLength System.out.println("setSideLength(3) results: " + newSideLength); //Setter methods for xCoord double newXCoord = 2.0; multiple.setXCoord(newXCoord); //Print newXCoord System.out.println("setXCoord(2.0) results: " + newXCoord); //Setter methods for yCoord
  • 5. double newYCoord = 2.0; multiple.setYCoord(newYCoord); //Print newXCoord System.out.println("setYCoord(2.0) results: " + newYCoord); //Setter methods for apothem double newApothem = 2.0; multiple.setApothem(newApothem); //Print newApothem System.out.println("setApothem(2.0) results: " + newApothem); Scanner scannerIn=new Scanner(System.in); //Set up to create 5 different polygons with new inputs by user //Repeat 5 times with for loop int userNumSides = 0; double userSideLength = 0.0; double userXCoord = 0.0; double userYCoord = 0.0; double userApothem = 0.0; //input the x & y coordinate, numSide, sideLength, and apothem for (int i = 0; i<5; i++) { System.out.print("Enter the number of polygon sides (ex 5): "); userNumSides = scannerIn.nextInt(); System.out.print("Enter the length of the polygon sides (ex 6.8): "); userSideLength = scannerIn.nextDouble(); System.out.print("Enter the x coordinate (ex 1.2): "); userXCoord = scannerIn.nextDouble(); System.out.print("Enter the y coordinate (ex 3.4): "); userYCoord = scannerIn.nextDouble(); System.out.print("Enter the length of apothem (ex 0.8): "); userApothem = scannerIn.nextDouble(); double userPerimeter = userNumSides * userSideLength; double userArea = 0.5 * userApothem * userPerimeter;
  • 6. //print results System.out.print("userNumSides() results: " + userNumSides); System.out.print("userSideLength() results: " + userSideLength); System.out.print("userXCoord() results: " + userXCoord); System.out.print("userYCoord() results: " + userYCoord); System.out.print("userApothem() results: " + userApothem); System.out.print("Perimeter of polygon is: " + userPerimeter); System.out.print("Area of polygon is: " + userArea); System.out.println("setNumSides(4) results: " + newNumSides); System.out.println("setSideLength(3) results: " + newSideLength); System.out.println("setXCoord(2.0) results: " + newXCoord); System.out.println("setYCoord(2.0) results: " + newYCoord); System.out.println("setApothem(2.0) results: " + newApothem); } } } Output: toString() results: numsides= 4, sideLength= 10.0 xCoord= 0.0, yCoord= 0.0, apothem= 5.0 getNumsides() results: 4 getSideLength() results: 10.0 getXCoord() results: 0.0 getYCoord() results: 0.0 getApothem() results: 5.0 getPerimeter() results: 20.0 getArea() results: 0.0 setNumSides(4) results: 4 setSideLength(3) results: 3.0 setXCoord(2.0) results: 2.0 setYCoord(2.0) results: 2.0 setApothem(2.0) results: 2.0 Enter the number of polygon sides (ex 5): 3 Enter the length of the polygon sides (ex 6.8): 4 Enter the x coordinate (ex 1.2): 1.2 Enter the y coordinate (ex 3.4): 3.4
  • 7. Enter the length of apothem (ex 0.8): 0.5 userNumSides() results: 3userSideLength() results: 4.0userXCoord() results: 1.2userYCoord() results: 3.4userApothem() results: 0.5Perimeter of polygon is: 12.0Area of polygon is: 3.0setNumSides(4) results: 4 setSideLength(3) results: 3.0 setXCoord(2.0) results: 2.0 setYCoord(2.0) results: 2.0 setApothem(2.0) results: 2.0 Enter the number of polygon sides (ex 5): Solution Polygon.java public class Polygon { private int numSides; private double sideLength; private double xCoord; private double yCoord; private double apothem; private double perimeter; private double area; //Constructor public Polygon (double xCentCoord, double yCentCoord, int countSides, double measLength, double measApothem, double measPerimeter) { xCoord = xCentCoord; yCoord = yCentCoord; numSides = countSides; sideLength = measLength; apothem = measApothem; perimeter = measPerimeter; } //No argument constructor public Polygon () { xCoord = 0.0; yCoord = 0.0; numSides = 4;
  • 8. sideLength = 10.0; apothem = 5.0; perimeter = 20.0; } //Setter Methods //setX() public void setXCoord(double xCentCoord) { xCoord = xCentCoord; } //setY() public void setYCoord(double yCentCoord) { yCoord = yCentCoord; } //setNumSides() public void setNumSides(int countSides) { numSides = countSides; } //setSideLength() public void setSideLength(double measLength) { sideLength = measLength; } //setApothem() public void setApothem(double measApothem) { apothem = measApothem; } //Getter methods //getXCoord public double getXCoord() { return xCoord; } //getYCoord public double getYCoord() { return yCoord; } //getNumSides public int getNumSides() {
  • 9. return numSides; } //getSideLength() public double getSideLength() { return sideLength; } //getApothem() public double getApothem() { return apothem; } //getPerimeter() public double getPerimeter() { return perimeter; } //getArea() public double getArea() { return area; } //Calculate for perimeter public double getPerimeter(Polygon multiple){ double perimeter = multiple.getNumSides() * multiple.getSideLength(); return perimeter; } //Calculate for area public double getArea(Polygon multiple) { double area = 0.5 * multiple.getApothem() * multiple.getPerimeter(); return area; } //toString method public String toString() { String str = "numsides= " + numSides + ", sideLength= " + sideLength; return str; }
  • 10. } TestPolygon.java //import Scanner import java.util.Scanner; public class TestPolygon { public static void main(String[] args) { //Construct a point with x = 1.0, y = 1.0 Polygon multiple = new Polygon(); //Display the values using toString System.out.println("toString() results: " + multiple.toString()); //Call the getter methods double xCoord2 = multiple.getXCoord(); double yCoord2 = multiple.getYCoord(); int numSides2 = multiple.getNumSides(); double sideLength2 = multiple.getSideLength(); double apothem2 = multiple.getApothem(); double perimeter2 = multiple.getPerimeter(); double area2 = multiple.getArea(); //Print results System.out.println("xCoord= " + xCoord2 + ", yCoord= " + yCoord2 + ", apothem= " +apothem2); System.out.println("getNumsides() results: " + numSides2); System.out.println("getSideLength() results: " + sideLength2); System.out.println("getXCoord() results: " + xCoord2); System.out.println("getYCoord() results: " + yCoord2); System.out.println("getApothem() results: " + apothem2); System.out.println("getPerimeter() results: " +perimeter2); System.out.println("getArea() results: " + area2); //Setter methods for numSides int newNumSides = 4; multiple.setNumSides(newNumSides); //Print newNumSides System.out.println("setNumSides(4) results: " + newNumSides);
  • 11. //Setter methods for sideLength double newSideLength = 3; multiple.setSideLength(newSideLength); //Print newSideLength System.out.println("setSideLength(3) results: " + newSideLength); //Setter methods for xCoord double newXCoord = 2.0; multiple.setXCoord(newXCoord); //Print newXCoord System.out.println("setXCoord(2.0) results: " + newXCoord); //Setter methods for yCoord double newYCoord = 2.0; multiple.setYCoord(newYCoord); //Print newXCoord System.out.println("setYCoord(2.0) results: " + newYCoord); //Setter methods for apothem double newApothem = 2.0; multiple.setApothem(newApothem); //Print newApothem System.out.println("setApothem(2.0) results: " + newApothem); Scanner scannerIn=new Scanner(System.in); //Set up to create 5 different polygons with new inputs by user //Repeat 5 times with for loop int userNumSides = 0; double userSideLength = 0.0; double userXCoord = 0.0; double userYCoord = 0.0; double userApothem = 0.0; //input the x & y coordinate, numSide, sideLength, and apothem for (int i = 0; i<5; i++) { System.out.print("Enter the number of polygon sides (ex 5): ");
  • 12. userNumSides = scannerIn.nextInt(); System.out.print("Enter the length of the polygon sides (ex 6.8): "); userSideLength = scannerIn.nextDouble(); System.out.print("Enter the x coordinate (ex 1.2): "); userXCoord = scannerIn.nextDouble(); System.out.print("Enter the y coordinate (ex 3.4): "); userYCoord = scannerIn.nextDouble(); System.out.print("Enter the length of apothem (ex 0.8): "); userApothem = scannerIn.nextDouble(); double userPerimeter = userNumSides * userSideLength; double userArea = 0.5 * userApothem * userPerimeter; //print results System.out.print("userNumSides() results: " + userNumSides); System.out.print("userSideLength() results: " + userSideLength); System.out.print("userXCoord() results: " + userXCoord); System.out.print("userYCoord() results: " + userYCoord); System.out.print("userApothem() results: " + userApothem); System.out.print("Perimeter of polygon is: " + userPerimeter); System.out.print("Area of polygon is: " + userArea); System.out.println("setNumSides(4) results: " + newNumSides); System.out.println("setSideLength(3) results: " + newSideLength); System.out.println("setXCoord(2.0) results: " + newXCoord); System.out.println("setYCoord(2.0) results: " + newYCoord); System.out.println("setApothem(2.0) results: " + newApothem); } } } Output: toString() results: numsides= 4, sideLength= 10.0 xCoord= 0.0, yCoord= 0.0, apothem= 5.0 getNumsides() results: 4 getSideLength() results: 10.0 getXCoord() results: 0.0 getYCoord() results: 0.0 getApothem() results: 5.0
  • 13. getPerimeter() results: 20.0 getArea() results: 0.0 setNumSides(4) results: 4 setSideLength(3) results: 3.0 setXCoord(2.0) results: 2.0 setYCoord(2.0) results: 2.0 setApothem(2.0) results: 2.0 Enter the number of polygon sides (ex 5): 3 Enter the length of the polygon sides (ex 6.8): 4 Enter the x coordinate (ex 1.2): 1.2 Enter the y coordinate (ex 3.4): 3.4 Enter the length of apothem (ex 0.8): 0.5 userNumSides() results: 3userSideLength() results: 4.0userXCoord() results: 1.2userYCoord() results: 3.4userApothem() results: 0.5Perimeter of polygon is: 12.0Area of polygon is: 3.0setNumSides(4) results: 4 setSideLength(3) results: 3.0 setXCoord(2.0) results: 2.0 setYCoord(2.0) results: 2.0 setApothem(2.0) results: 2.0 Enter the number of polygon sides (ex 5):