SlideShare a Scribd company logo
1 of 5
The purpose of this assignment is to have you write a Java
program using methods to compute and output the area of an n
sided polygon where the area is defined by the following
mathematical formula: area = (n * (s * s))/(4 * tan(3.1416/n))
where s = length of a side of a regular polygon with all sides of
equal length and all angles are the same and n = the number of
sides. For this assignment set n = 5 for a pentagon and let the
side s vary from 1 to 20. Your output should let the size of a
side vary from 1 to 20. You should have one method to compute
the resulting area and another method to determine whether the
area is consider small, medium or large according to the
following table. Your column headings should include side,
area and classification.
Solution
Please follow the code and comments for dscription :
CODE :
import java.util.Scanner;
public class PolygonArea {
@SuppressWarnings("MalformedFormatString")
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of sides: ");
int numberOfSides = input.nextInt();
double side = 0;
System.out.println("The tabulated areas of the polygon
for different sides from 1 to 20 are as follows :");
System.out.println(" ");
System.out.format("%32s %10s %15s",
"SIDE", "AREA", "CLASSIFICATION");
for (int x = 1; x <= 20; x++) {
side = x;
double parea = area(numberOfSides, side);
String classification = cls(parea);
System.out.println(" ");
System.out.format("%32s %10s %15s", side,
parea, classification);
}
input.close();
}
public static double area(int n, double side) {
double answer = (n * (side * side)) / (4 *
(Math.tan((Math.PI / n))));
return answer;
}
public static String cls(double ar){
String classi;
if(ar<=10){
classi = "Small";
}
else if (ar>= 11 && ar <=25){
classi = "Medium";
}
else{
classi = "Large";
}
return classi;
}
}
OUTPUT :
Enter the number of sides:
5
The tabulated areas of the polygon for different sides from 1 to
20 are as follows :
SIDE AREA CLASSIFICATION
1.0 1.720477400588967 Small
2.0 6.881909602355868 Small
3.0 15.484296605300703
Medium
4.0 27.52763840942347 Large
5.0 43.01193501472417 Large
6.0 61.93718642120281 Large
7.0 84.30339262885938 Large
8.0 110.11055363769388 Large
9.0 139.35866944770632 Large
10.0 172.0477400588967 Large
11.0 208.177765471265 Large
12.0 247.74874568481124 Large
13.0 290.7606806995354 Large
14.0 337.21357051543754 Large
15.0 387.10741513251753 Large
16.0 440.44221455077553 Large
17.0 497.2179687702114 Large
18.0 557.4346777908253 Large
19.0 621.092341612617 Large
20.0 688.1909602355868 Large
Hope this is helpful.
 The purpose of this assignment is to have you write a Java program us.docx

More Related Content

Similar to The purpose of this assignment is to have you write a Java program us.docx

Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++Osama Al-Mohaia
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdfssuser476810
 
Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfhullibergerr25980
 
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxinfantsuk
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaVijiPriya Jeyamani
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplicationbabuk110
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Amairullah Khan Lodhi
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solutionAnimesh Chaturvedi
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFTvikram mahendra
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersSheila Sinclair
 

Similar to The purpose of this assignment is to have you write a Java program us.docx (20)

Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
 
Ansi c
Ansi cAnsi c
Ansi c
 
C-programs
C-programsC-programs
C-programs
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdf
 
Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdf
 
Ch3
Ch3Ch3
Ch3
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriya
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
 
How big-is-your-graph
How big-is-your-graphHow big-is-your-graph
How big-is-your-graph
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFT
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
 

More from Komlin1

Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docxTheodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docxKomlin1
 
Theory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docxTheory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docxKomlin1
 
Theory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docxTheory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docxKomlin1
 
There are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docxThere are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docxKomlin1
 
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docxThere are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docxKomlin1
 
Theoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docxTheoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docxKomlin1
 
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docxTHEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docxKomlin1
 
Theories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docxTheories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docxKomlin1
 
Thematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docxThematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docxKomlin1
 
The written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docxThe written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docxKomlin1
 
The World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docxThe World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docxKomlin1
 
The world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docxThe world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docxKomlin1
 
the    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docxthe    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docxKomlin1
 
The word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docxThe word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docxKomlin1
 
The Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docxThe Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docxKomlin1
 
The Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docxThe Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docxKomlin1
 
The wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docxThe wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docxKomlin1
 
The Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docxThe Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docxKomlin1
 
The United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docxThe United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docxKomlin1
 
The Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docxThe Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docxKomlin1
 

More from Komlin1 (20)

Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docxTheodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
 
Theory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docxTheory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docx
 
Theory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docxTheory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docx
 
There are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docxThere are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docx
 
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docxThere are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
 
Theoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docxTheoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docx
 
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docxTHEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
 
Theories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docxTheories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docx
 
Thematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docxThematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docx
 
The written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docxThe written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docx
 
The World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docxThe World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docx
 
The world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docxThe world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docx
 
the    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docxthe    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docx
 
The word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docxThe word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docx
 
The Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docxThe Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docx
 
The Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docxThe Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docx
 
The wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docxThe wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docx
 
The Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docxThe Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docx
 
The United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docxThe United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docx
 
The Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docxThe Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docx
 

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

The purpose of this assignment is to have you write a Java program us.docx

  • 1. The purpose of this assignment is to have you write a Java program using methods to compute and output the area of an n sided polygon where the area is defined by the following mathematical formula: area = (n * (s * s))/(4 * tan(3.1416/n)) where s = length of a side of a regular polygon with all sides of equal length and all angles are the same and n = the number of sides. For this assignment set n = 5 for a pentagon and let the side s vary from 1 to 20. Your output should let the size of a side vary from 1 to 20. You should have one method to compute the resulting area and another method to determine whether the area is consider small, medium or large according to the following table. Your column headings should include side, area and classification. Solution Please follow the code and comments for dscription : CODE : import java.util.Scanner; public class PolygonArea { @SuppressWarnings("MalformedFormatString") public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the number of sides: "); int numberOfSides = input.nextInt();
  • 2. double side = 0; System.out.println("The tabulated areas of the polygon for different sides from 1 to 20 are as follows :"); System.out.println(" "); System.out.format("%32s %10s %15s", "SIDE", "AREA", "CLASSIFICATION"); for (int x = 1; x <= 20; x++) { side = x; double parea = area(numberOfSides, side); String classification = cls(parea); System.out.println(" "); System.out.format("%32s %10s %15s", side, parea, classification); } input.close(); } public static double area(int n, double side) { double answer = (n * (side * side)) / (4 * (Math.tan((Math.PI / n)))); return answer; }
  • 3. public static String cls(double ar){ String classi; if(ar<=10){ classi = "Small"; } else if (ar>= 11 && ar <=25){ classi = "Medium"; } else{ classi = "Large"; } return classi; } } OUTPUT : Enter the number of sides: 5 The tabulated areas of the polygon for different sides from 1 to 20 are as follows : SIDE AREA CLASSIFICATION 1.0 1.720477400588967 Small 2.0 6.881909602355868 Small
  • 4. 3.0 15.484296605300703 Medium 4.0 27.52763840942347 Large 5.0 43.01193501472417 Large 6.0 61.93718642120281 Large 7.0 84.30339262885938 Large 8.0 110.11055363769388 Large 9.0 139.35866944770632 Large 10.0 172.0477400588967 Large 11.0 208.177765471265 Large 12.0 247.74874568481124 Large 13.0 290.7606806995354 Large 14.0 337.21357051543754 Large 15.0 387.10741513251753 Large 16.0 440.44221455077553 Large 17.0 497.2179687702114 Large 18.0 557.4346777908253 Large 19.0 621.092341612617 Large 20.0 688.1909602355868 Large Hope this is helpful.