SlideShare a Scribd company logo
1 of 6
Download to read offline
Polygon .java
package chegg2;
public class Polygon {
// Variables
private int numSides;
private double sideLength;
private double xCord;
private double yCord;
// Default Constructor
public Polygon () {
numSides = 3;
sideLength = 5.0;
xCord = 0.0;
yCord = 0.0;
}
// Constructor
public Polygon (int pSides, double numLength, double numXCord, double numYCord) {
numSides = pSides;
sideLength = numLength;
xCord = numXCord;
yCord = numYCord;
}
// Setter
public void setSides(int mSides) {
numSides = mSides;
System.out.println("setSides() results: "+this.numSides);
}
// Getter
public int getSides() {
return numSides;
}
}
TestPolygon .java
package chegg2;
import java.util.Scanner;
public class TestPolygon {
public static void main(String[] args) {
Polygon poly[] = new Polygon[2];
Polygon poly2 = new Polygon();
poly[0] = poly2;
Scanner input = new Scanner(System.in);
for(int i=1; i<2; i++){
Polygon obj = new Polygon();
System.out.println("New Polygons");
System.out.println("--------------------------------------------------");
System.out.print("Enter Number of Sides:");
obj.setSides(input.nextInt());
poly[i] = obj;
} input.close();
System.out.println("Polygons");
System.out.println("--------------------------------------------------");
for(int i=0; i<2; i++) {
poly[i].setSides(poly[i].getSides());
}
}
}
Output:
run:
New Polygons
--------------------------------------------------
Enter Number of Sides:9
setSides() results: 9
Polygons
--------------------------------------------------
setSides() results: 3
setSides() results: 9
BUILD SUCCESSFUL (total time: 1 second)
Solution
Polygon .java
package chegg2;
public class Polygon {
// Variables
private int numSides;
private double sideLength;
private double xCord;
private double yCord;
// Default Constructor
public Polygon () {
numSides = 3;
sideLength = 5.0;
xCord = 0.0;
yCord = 0.0;
}
// Constructor
public Polygon (int pSides, double numLength, double numXCord, double numYCord) {
numSides = pSides;
sideLength = numLength;
xCord = numXCord;
yCord = numYCord;
}
// Setter
public void setSides(int mSides) {
numSides = mSides;
System.out.println("setSides() results: "+this.numSides);
}
// Getter
public int getSides() {
return numSides;
}
}
TestPolygon .java
package chegg2;
import java.util.Scanner;
public class TestPolygon {
public static void main(String[] args) {
Polygon poly[] = new Polygon[2];
Polygon poly2 = new Polygon();
poly[0] = poly2;
Scanner input = new Scanner(System.in);
for(int i=1; i<2; i++){
Polygon obj = new Polygon();
System.out.println("New Polygons");
System.out.println("--------------------------------------------------");
System.out.print("Enter Number of Sides:");
obj.setSides(input.nextInt());
poly[i] = obj;
} input.close();
System.out.println("Polygons");
System.out.println("--------------------------------------------------");
for(int i=0; i<2; i++) {
poly[i].setSides(poly[i].getSides());
}
}
}
Output:
run:
New Polygons
--------------------------------------------------
Enter Number of Sides:9
setSides() results: 9
Polygons
--------------------------------------------------
setSides() results: 3
setSides() results: 9
BUILD SUCCESSFUL (total time: 1 second)

More Related Content

Similar to Polygon .java package chegg2;public class Polygon { Var.pdf

C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
Paulo Morgado
 
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docxch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
cravennichole326
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
anurag1231
 
Dcom vs. corba
Dcom vs. corbaDcom vs. corba
Dcom vs. corba
Mohd Arif
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
aquadreammail
 

Similar to Polygon .java package chegg2;public class Polygon { Var.pdf (20)

C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Manual tecnic sergi_subirats
Manual tecnic sergi_subiratsManual tecnic sergi_subirats
Manual tecnic sergi_subirats
 
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docxch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
ch12.DS_Store__MACOSXch12._.DS_Storech12section_1.D.docx
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
Dcom vs. corba
Dcom vs. corbaDcom vs. corba
Dcom vs. corba
 
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
 
Dependency Injection for Android
Dependency Injection for AndroidDependency Injection for Android
Dependency Injection for Android
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Test Engine
Test EngineTest Engine
Test Engine
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
 
C++ via C#
C++ via C#C++ via C#
C++ via C#
 
C++ Programming - 9th Study
C++ Programming - 9th StudyC++ Programming - 9th Study
C++ Programming - 9th Study
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Test Engine
Test EngineTest Engine
Test Engine
 
Static Analysis in IDEA
Static Analysis in IDEAStatic Analysis in IDEA
Static Analysis in IDEA
 

More from aplolomedicalstoremr

This is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdfThis is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdf
aplolomedicalstoremr
 
Statistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdfStatistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdf
aplolomedicalstoremr
 
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdfSecondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
aplolomedicalstoremr
 
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdfOutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
aplolomedicalstoremr
 
JUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdfJUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdf
aplolomedicalstoremr
 
Incapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdfIncapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdf
aplolomedicalstoremr
 
Go with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdfGo with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdf
aplolomedicalstoremr
 
Flexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdfFlexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdf
aplolomedicalstoremr
 
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdfEnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
aplolomedicalstoremr
 
Classification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdfClassification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdf
aplolomedicalstoremr
 
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdfAssets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
aplolomedicalstoremr
 
ANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdfANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdf
aplolomedicalstoremr
 

More from aplolomedicalstoremr (20)

You have to leave solids and liquids out of the equation. This lea.pdf
You have to leave solids and liquids out of the equation. This lea.pdfYou have to leave solids and liquids out of the equation. This lea.pdf
You have to leave solids and liquids out of the equation. This lea.pdf
 
Tungsten is a body centered cubic latticeSolutionTungsten is a.pdf
Tungsten is a body centered cubic latticeSolutionTungsten is a.pdfTungsten is a body centered cubic latticeSolutionTungsten is a.pdf
Tungsten is a body centered cubic latticeSolutionTungsten is a.pdf
 
This is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdfThis is the final code which meets your requirement.Than youCard.j.pdf
This is the final code which meets your requirement.Than youCard.j.pdf
 
Statistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdfStatistics is the mathematical science involving the collection, ana.pdf
Statistics is the mathematical science involving the collection, ana.pdf
 
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdfSecondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
Secondary phloemApples (Malus communis, M. pumila, & M. sylvestr.pdf
 
probability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdf
probability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdfprobability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdf
probability that the trajectory falls between 1.2 and 1.4 =(1.4-1.2).pdf
 
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdfOutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
OutputFibonacci till 20 0 1 1 2 3 5 8 13 21 .pdf
 
Matter is made up of electrically charge particle but the Constituen.pdf
Matter is made up of electrically charge particle but the Constituen.pdfMatter is made up of electrically charge particle but the Constituen.pdf
Matter is made up of electrically charge particle but the Constituen.pdf
 
it is a polynomial of degree 3Solutionit is a polynomial of de.pdf
it is a polynomial of degree 3Solutionit is a polynomial of de.pdfit is a polynomial of degree 3Solutionit is a polynomial of de.pdf
it is a polynomial of degree 3Solutionit is a polynomial of de.pdf
 
JUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdfJUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdf
 
Intitially take a graph sheet and plot the points and the whole figu.pdf
Intitially take a graph sheet and plot the points and the whole figu.pdfIntitially take a graph sheet and plot the points and the whole figu.pdf
Intitially take a graph sheet and plot the points and the whole figu.pdf
 
Incapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdfIncapsula Enterprise is the best mitigation service provider with th.pdf
Incapsula Enterprise is the best mitigation service provider with th.pdf
 
Go with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdfGo with the most obvious one first...Carboxylic Acids will have a.pdf
Go with the most obvious one first...Carboxylic Acids will have a.pdf
 
Flexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdfFlexible benefit plans gives employees a choice between qualified be.pdf
Flexible benefit plans gives employees a choice between qualified be.pdf
 
f(x) = cos(x)Solutionf(x) = cos(x).pdf
f(x) = cos(x)Solutionf(x) = cos(x).pdff(x) = cos(x)Solutionf(x) = cos(x).pdf
f(x) = cos(x)Solutionf(x) = cos(x).pdf
 
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdfEnvironmentLet assume the environment is a grid of colored tiles(.pdf
EnvironmentLet assume the environment is a grid of colored tiles(.pdf
 
Classification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdfClassification of organisms is based upon a number of physical and p.pdf
Classification of organisms is based upon a number of physical and p.pdf
 
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdfAssets=Liabilities+Paid in capital+Retained earnings1..pdf
Assets=Liabilities+Paid in capital+Retained earnings1..pdf
 
Hypothesis Test for population variance If we have a sample fro.pdf
 Hypothesis Test for population variance If we have a sample fro.pdf Hypothesis Test for population variance If we have a sample fro.pdf
Hypothesis Test for population variance If we have a sample fro.pdf
 
ANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdfANSWERFundamental configurations of Windows printer Deployments.pdf
ANSWERFundamental configurations of Windows printer Deployments.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 

Polygon .java package chegg2;public class Polygon { Var.pdf

  • 1. Polygon .java package chegg2; public class Polygon { // Variables private int numSides; private double sideLength; private double xCord; private double yCord; // Default Constructor public Polygon () { numSides = 3; sideLength = 5.0; xCord = 0.0; yCord = 0.0; } // Constructor public Polygon (int pSides, double numLength, double numXCord, double numYCord) { numSides = pSides; sideLength = numLength; xCord = numXCord; yCord = numYCord; } // Setter public void setSides(int mSides) { numSides = mSides;
  • 2. System.out.println("setSides() results: "+this.numSides); } // Getter public int getSides() { return numSides; } } TestPolygon .java package chegg2; import java.util.Scanner; public class TestPolygon { public static void main(String[] args) { Polygon poly[] = new Polygon[2]; Polygon poly2 = new Polygon(); poly[0] = poly2; Scanner input = new Scanner(System.in); for(int i=1; i<2; i++){ Polygon obj = new Polygon(); System.out.println("New Polygons"); System.out.println("--------------------------------------------------"); System.out.print("Enter Number of Sides:"); obj.setSides(input.nextInt()); poly[i] = obj; } input.close(); System.out.println("Polygons");
  • 3. System.out.println("--------------------------------------------------"); for(int i=0; i<2; i++) { poly[i].setSides(poly[i].getSides()); } } } Output: run: New Polygons -------------------------------------------------- Enter Number of Sides:9 setSides() results: 9 Polygons -------------------------------------------------- setSides() results: 3 setSides() results: 9 BUILD SUCCESSFUL (total time: 1 second) Solution Polygon .java package chegg2; public class Polygon { // Variables private int numSides; private double sideLength; private double xCord; private double yCord; // Default Constructor public Polygon () {
  • 4. numSides = 3; sideLength = 5.0; xCord = 0.0; yCord = 0.0; } // Constructor public Polygon (int pSides, double numLength, double numXCord, double numYCord) { numSides = pSides; sideLength = numLength; xCord = numXCord; yCord = numYCord; } // Setter public void setSides(int mSides) { numSides = mSides; System.out.println("setSides() results: "+this.numSides); } // Getter public int getSides() { return numSides; } } TestPolygon .java package chegg2; import java.util.Scanner; public class TestPolygon { public static void main(String[] args) { Polygon poly[] = new Polygon[2];
  • 5. Polygon poly2 = new Polygon(); poly[0] = poly2; Scanner input = new Scanner(System.in); for(int i=1; i<2; i++){ Polygon obj = new Polygon(); System.out.println("New Polygons"); System.out.println("--------------------------------------------------"); System.out.print("Enter Number of Sides:"); obj.setSides(input.nextInt()); poly[i] = obj; } input.close(); System.out.println("Polygons"); System.out.println("--------------------------------------------------"); for(int i=0; i<2; i++) { poly[i].setSides(poly[i].getSides()); } } } Output: run: New Polygons -------------------------------------------------- Enter Number of Sides:9 setSides() results: 9 Polygons