Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using Java, and comment codes. menu & main The code for displaying a menu and allowing the user to pick an option is already written

using Java, and comment codes.

menu & main

The code for displaying a menu and allowing the user to pick an option is already written in the menu() method. In main, you need to call it and then based on the String that is returned called the appropriate drawing method. The calls to the various methods below are up to you. main is there to demonstrate that your code works. You can certainly hard code in a particular call, or you may do like I did in the demo and have some randomization, using the given rand method.

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 an nickname.

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.

image text in transcribed

In this next image 720 line segments were specified again with line length 100.

image text in transcribed

If n lines are drawn, then the angle between them is 360.0 / n. Furthermore the color of the line depends on the angle the turtle is facing when drawing that line. A line drawn at angle ang has the HSB/HSV color of (ang / 360, 1, 1).

so far:

import edu.gatech.mediacomp.Turtle; import edu.gatech.mediacomp.World; import edu.ventura.support.AnimatedTurtle; import edu.ventura.support.EndWorld; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import java.awt.*; import java.util.concurrent.ThreadLocalRandom; public class HelloTurtles { /**  * Use the given turtle to draw your name.  * @param t the turtle to use for drawing.  */  public static void drawName(Turtle t) { // TODO: your implementation here  } // end drawName   /**  * Draws the specified number of lines, rotating 360.0 / n between  * each line. The color of each line is determined by the angle  * the turtle is facing when drawing that line.  * A line drawn at angle ang has the HSB/HSV color of (ang / 360, 1, 1).  * You may want to refer to  * https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html#getHSBColor-float-float-float-  *  * @param t the turtle to use to draw.  * @param numLines the number of line segments.  * @param lineLength the length of each line segment.  */  public static void radial(Turtle t, int numLines, int lineLength) { // TODO: your implementation here  } // end radial   /**  * Draws the specified number of regular polygons,  * each starting at the same place, however,  * after each polygon is drawn the turtle turns 360 / numPolys degrees  *  * @param t the turtle to use to draw.  * @param numPolys the number of polygons to draw.  * @param numSides the number of sides of each polygon.  * @param sideLen the length of each side of each polygon.  */  public static void manyPolygons(Turtle t, int numPolys, int numSides, int sideLen) { // TODO: your implementation here  } // end manyPolygons   /**  * Draws a regular polygon of the specified number of sides and length of side.  *  * @param t the turtle to use to draw.  * @param numSides the number of sides of each polygon.  * @param sideLen the length of each side of each polygon.  */  public static void drawPolygon(Turtle t, int numSides, int sideLen) { // TODO: your implementation here  } // end drawPolygon   /**  * Entry point of the program.  */  public static void main(String[] args) { // TODO: your implementation here   } // end main   /**  * Returns a random number between low (inclusive) and high (exclusive).  * @param low the lower (inclusive) part of the range.  * @param high the upper (exclusive) part of the range.  * @return a random number between low (inclusive) and high (exclusive).  */  public static int rand(int low, int high) { return ThreadLocalRandom.current().nextInt(low, high); } /**  * Displays the menu and returns the value the user selected.  * Quits the program if the user selects Cancel.  *  * NOTE: Remember to compare strings using the .equals method.  *  * @return one of "Name", "Polygon", "Many Polygons", "Radial"  */  public static String menu() { JPanel panel = new JPanel(); panel.add(new JRadioButton("radio")); String values[] = {"Name", "Polygon", "Many Polygons", "Radial"}; Object choice = JOptionPane.showInputDialog(null, "Choose the demo to show", "Choose Demo", JOptionPane.DEFAULT_OPTION, null, values, "0"); if (choice == null) { System.exit(0); } return choice.toString(); } // end menu  } // end class HelloTurtles  
World Turtle Speed Slowest Fastest

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

What are the total sales orders for November?

Answered: 1 week ago