Extension 4 - Draw n-gon For the final pre-defined choice of extension, you must implement a method that draws a regular polygon parameterized number of sides and length for these sides. As the shape is regular, each side will have the s length. Examples of regular polygons are the equilateral triangle, square, pentagon, hexagon, etc... This method must have the following header: public static void drawNgon (Turtle t, int numSides, int side Length) { The parameters are used as follows: • Turtle t o Used to draw the random shape • int numSides o The number of sides to draw. If this value is 5, then a pentagon should be drawn for example. int side Length o The length of each side to draw The angle that the Turtle should turn after each side can be found using the following formula: double angle = 360.0 / numSides Using this formula, the angle that the Turtle would need to turn each time to make a pentagon would be: 360.0/5 = 72.0
Extension 4 - Draw n-gon For the final pre-defined choice of extension, you must implement a method that draws a regular polygon parameterized number of sides and length for these sides. As the shape is regular, each side will have the s length. Examples of regular polygons are the equilateral triangle, square, pentagon, hexagon, etc... This method must have the following header: public static void drawNgon (Turtle t, int numSides, int side Length) { The parameters are used as follows: • Turtle t o Used to draw the random shape • int numSides o The number of sides to draw. If this value is 5, then a pentagon should be drawn for example. int side Length o The length of each side to draw The angle that the Turtle should turn after each side can be found using the following formula: double angle = 360.0 / numSides Using this formula, the angle that the Turtle would need to turn each time to make a pentagon would be: 360.0/5 = 72.0
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Use java
See the image for requirements
![Extension 4 - Draw n-gon
For the final pre-defined choice of extension, you must implement a method that draws a regular polygon w
parameterized number of sides and length for these sides. As the shape is regular, each side will have the s
length.
Examples of regular polygons are the equilateral triangle, square, pentagon, hexagon, etc...
This method must have the following header:
public static void drawNgon (Turtle t, int numSides, int side Length) {
The parameters are used as follows:
• Turtle t
o Used to draw the random shape
int numSides
o The number of sides to draw. If this value is 5, then a pentagon should be drawn for example.
int side Length
o The length of each side to draw
The angle that the Turtle should turn after each side can be found using the following formula:
double angle = 360.0 / numSides
Using this formula, the angle that the Turtle would need to turn each time to make a pentagon would be:
360.0/5 = 72.0](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6c680976-d041-43f6-b2b7-59630778639d%2Fb4981a90-ff84-4043-9229-ea4527bf8c6c%2Fvo5jdp9_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Extension 4 - Draw n-gon
For the final pre-defined choice of extension, you must implement a method that draws a regular polygon w
parameterized number of sides and length for these sides. As the shape is regular, each side will have the s
length.
Examples of regular polygons are the equilateral triangle, square, pentagon, hexagon, etc...
This method must have the following header:
public static void drawNgon (Turtle t, int numSides, int side Length) {
The parameters are used as follows:
• Turtle t
o Used to draw the random shape
int numSides
o The number of sides to draw. If this value is 5, then a pentagon should be drawn for example.
int side Length
o The length of each side to draw
The angle that the Turtle should turn after each side can be found using the following formula:
double angle = 360.0 / numSides
Using this formula, the angle that the Turtle would need to turn each time to make a pentagon would be:
360.0/5 = 72.0
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Thanks you so much!
Another questions: this is my code (see image), and I was trying to let the turtle to draw 4 different sizes sqaures, but after I ran my code, the turtle drew out 4 same size squares, where or how should I fix it(or update it)?
thank you.
![53
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
t.down();
public static void drawRandomS (Turtle t, Random rand, int numSquares, int maxSize) { // Extension
int randomSize = rand.nextInt (maxSize - 0 + 1) + 0;
for (int square = 0; square < numSquares; square++) {
for (int k = 0; k < 4; k++) {
t. forward (randomSize);
t.left (90);
}
}
}
t.up();
t. forward (120);
t.down();
t.up();
t. forward (200);
t.down();
/home/Shapes.java 61:28 Spaces: 4 (Auto)
Console Terminal
X Exceeded wall time](https://content.bartleby.com/qna-images/question/6c680976-d041-43f6-b2b7-59630778639d/f4e253ce-b7cc-47cb-a6d6-c58edf323b68/k2jluu_thumbnail.jpeg)
Transcribed Image Text:53
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
t.down();
public static void drawRandomS (Turtle t, Random rand, int numSquares, int maxSize) { // Extension
int randomSize = rand.nextInt (maxSize - 0 + 1) + 0;
for (int square = 0; square < numSquares; square++) {
for (int k = 0; k < 4; k++) {
t. forward (randomSize);
t.left (90);
}
}
}
t.up();
t. forward (120);
t.down();
t.up();
t. forward (200);
t.down();
/home/Shapes.java 61:28 Spaces: 4 (Auto)
Console Terminal
X Exceeded wall time
Solution
Follow-up Question
Can you provide a screenshot? It's a little bit hard to read like this
thank you
Solution
Follow-up Question
Thank you. But can you use the parameters and the formula given in the image??
Solution
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education