Write the code to have the turtle draw a regular polygon with the specified number of sides and specified side length

computer science

Description

You must use the starter IntelliJ and must make use of EndWorld (in place of World) and AnimatedTurtle (instead of Turtle).

Starter Project

HelloTurtlesStarter.zip

Download, unzip, and open the starter project in IntelliJ.

Demo

Below is a video showing how the program should work, sans drawName, as it is trivial and also does not require any user input.

hello-turtles-demo.mp4Play media comment.

menu, solution, & main

The code for displaying a menu and allowing the user to pick an option is already written in the menu() method.  In the solution() method, a call to the menu() method has been provided.  You must write the code that gets the appropriate user input based off the selection returned by menu and then calls the appropriate method (e.g. drawName, drawPolygon, etc.). 

User Input

As shown in the demo you are required to read in the parameters for the different methods by prompting the user graphically.  Special Topic 4.5 of our textbook shows how to use JOptionPane.showInputDialog to read input from a user and convert it into an integer.  You are NOT required to do input validation (i.e., you are NOT required to ensure that the user enters only a number).  You are strongly encouraged, but not required, to create a separate method named getInt that takes a prompt and returns the integer entered by the user and then make calls to that method for reading the user input.

Drawing Your Name

In the method drawName, make the turtle draw out your first name.  If your first name has more than 5 letters, you may use a nickname or the first 5 letters of your name.

Drawing A Regular Polygon

Write the code to have the turtle draw a regular polygon with the specified number of sides and specified side length.

Drawing Multiple Polygons

In the manyPolygons methods,  write the code to have the turtle draws the specified number of regular polygons, each starting at the same place, however,
 after each polygon is drawn the turtle turns 360.0 / numPolys degrees.

Some calls to manyPolygons to try out:

·         manyPolygons(t, 45, 3, 100)

·         manyPolygons(t, 60, 30, 20)

Drawing Radiating Lines

The first image was generated calling the radial method and specifying 15 line segments and a line length of 100.


Related Questions in computer science category