Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment we'll write a class with static methods that add some extra features to StdDraw (without modifying StdDraw itself). Your static methods should

In this assignment we'll write a class with static methods that add some extra features to StdDraw (without modifying StdDraw itself).

Your static methods should be written in a class called UnStdDraw, which you should put in the unstddraw package. The method you'll write are:

void filledRegularNgon(centerX, centerY, radius, n)

This will draw a regular n-gon (a polygon with n sides, all the same length, all with equal angles).

void spiral( centerX, centerY, maxRadius, spinRate, numSegments)

This will draw a spiral centered at (x, y). The maxRadius determines how large the spiral will be. A low spin rate will be basically a line out from the center. A high spin rate will have more circles. The spiral will be consist of many line segments. The numSegments parameters says how many to use to draw it.

A quick refresher on the geometry/trigonometry you'll need for this assignment:

All points on a circle can be written as:

x = xCenter + radius*cos(angle)

y = yCenter + radius*sin(angle)

A spiral is simply a circle where the radius changes depending on the angle (the spinRate parameter above controls this relationship), and as you increase n, a regular Ngon looks more and more like a circle. Take some time, experiment, and try to come up with a solution on your own. Adapting a bit of math to create a useful program (or method) is an important skill for a computer scientist, and you should develop your skills during this assignment.

In addition to these new methods, define 3 static color constants in UnStdDraw to broaden your palette. These should be colors with names that are not already in StdDraw (for example fuscia, mauve, neon-carrot, etc).

Finally, we want to keep track of how popular these new methods are. For each method, add a static variable that counts how many times the method is called. Write getter methods for each of those variables.

To test your new code, create a class named Driver. In your driver, use your UnStdDraw methods and colors (and StdDraw methods, that you need, or want to include) to draw a pretty picture. Also print out the number of times each each of your methods was called. For example, my pretty picture is shown below. It contains a hexagon, a 20-gon, and a spiral in my new colors SEA_FOAM and MIDNIGHT_BLUE. The counter variable for the filledNgon method is 2, and the counter for the spiral method is 1.

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

ISBN: 1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago