JAVA * PROBLEM 3: The following function draws mickey mouse, if you call it like
ID: 3906407 • Letter: J
Question
JAVA
* PROBLEM 3: The following function draws mickey mouse, if you call it like
* this from main:
*
* <pre>
* draw (.5, .5, .25);
* </pre>
*
* Change the code to draw mickey moose instead. Your solution should be
* recursive.
*
* Before picture: http://fpl.cs.depaul.edu/jriely/ds1/images/MickeyMouse.png
* After picture: http://fpl.cs.depaul.edu/jriely/ds1/images/MickeyMoose.png
*
* You may not use any "fields" to solve this problem (a field is a variable
* that is declared "outside" of the function declaration --- either before
* or after).
*/
public static void draw (double centerX, double centerY, double radius) {
if (radius < .0005) return;
StdDraw.setPenColor (StdDraw.LIGHT_GRAY);
StdDraw.filledCircle (centerX, centerY, radius);
StdDraw.setPenColor (StdDraw.BLACK);
StdDraw.circle (centerX, centerY, radius);
double change = radius * 0.90;
StdDraw.setPenColor (StdDraw.LIGHT_GRAY);
StdDraw.filledCircle (centerX+change, centerY+change, radius/2);
StdDraw.setPenColor (StdDraw.BLACK);
StdDraw.circle (centerX+change, centerY+change, radius/2);
StdDraw.setPenColor (StdDraw.LIGHT_GRAY);
StdDraw.filledCircle (centerX-change, centerY+change, radius/2);
StdDraw.setPenColor (StdDraw.BLACK);
StdDraw.circle (centerX-change, centerY+change, radius/2);
}
Explanation / Answer
Given below is the modified code for the question.
Please do rate the answer if it was helpful. Thank you
public static void draw (double centerX, double centerY, double radius) {
if (radius < .0005) return;
StdDraw.setPenColor (StdDraw.LIGHT_GRAY);
StdDraw.filledCircle (centerX, centerY, radius);
StdDraw.setPenColor (StdDraw.BLACK);
StdDraw.circle (centerX, centerY, radius);
double change = radius * 0.90;
draw(centerX+change, centerY+change, radius/2);
draw (centerX-change, centerY+change, radius/2);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.