Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java a. Modify the code by adding a parameter so that the turtle can turn left in any number of degrees: I. Refactor the

in java image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
a. Modify the code by adding a parameter so that the turtle can turn left in any number of degrees: I. Refactor the turnLeft90 method so it is now named turnLeft. ii. Add a double parameter to this method that will represent the number of degrees to turn. ii. Modify the method body so that the call to this.left(90); replaces the literal value 90 with the name of the parameter. iv. Add and complete an @param tag to the method specification identifying the new parameter. v. Delete the turn Left30 method and its specification because we have the new turnLeft method. b. Compile the code and fix the compilations errors by calling the new turnLeft method. At this point the DoodleTurtle class should compile, but the DoodleController will not as the turnLeft90 and turnLeft30 methods no longer exist. For example, if there was a statement like the following: this little Turtle.turnleft300); it would now become this little Turtle.turn Left(30); i. If there are multiple consecutive calls to turn, refactor those to a single call. For example, two calls to turnleft901) would be one call to the new method passing in 180 as the argument. // TODO Part 1 B.1 /** * Turns the turtle 90 degrees to its left. * @precondition none * @postcondition none */ public void turnleft90() { turnleft(); } /**** 69 700 71 72 73 74 75 760 77 78 790 80 81 820 83 84 85 86 87 88 89 90 91 920 93 94 95 */ private void turnleft() { this. left(90); } * /** * Turns the turtle 30 degrees to its left. * @precondition none * @postcondition none */ public void turnLeft300) { this. left(30.0); } package edu.westga.cs1301.projecti.controllers; 30 import edu.vestga.cs1381.projecti.model.DoodleTurtle:( 5 60/ 7 8 9 10 11 / 14 Uses turtle objects to draw on the screen. Gauthor C51301 Oversion Spring 2021 12 public class DoodleController { 13 private DoodleTurtle big Turtle; private Doodleturtle littleTurtle; 15 160 17 Creates and initializes a new DoodleController object. eprecondition bigTurtle != null AND LittleTurtle != null epostcondition none 21 @param bigTurtle The turtle will be the bigger of the two turtles. @param littleTurtle The turtle will be the smaller of the two turtles. 27 public DoodleControllercadleTurtle bigturtle, Doodle Yurtle LittleTurtte) { 29 this.uttleTurtle - uttleTurtles 18 19 20 22 28 30 36 46 48 49 50 "DoodleTurtle.java DoodleController.java 350 /A Draws a figure on the screen using turtles. 37 3B precondition none 39 Opostcondition none 40 +/ 410 public void draw() { 42 // TODO Part 1.1 43 this. moveBigTurtleToPositionForFirstRectangle(); 44 this.drawRectanglewithBigTurtle(); this.noveLittleTurtleToPositionForFirstRectangle(); this.drawRectanglewithlittleTurtle(); this.noveBigTurtleTopositionForSecondRectangle(); this.drawfectangleWithBigTurtle(); this moveLittleTurtleToPositionForSecond Rectanglel): 53 this.drawRectanglewithlittleTurtle(): 54 } 55 566 private void moveBigTurtleTopositionForFirstRectangle() { 57 this.bigTurtle.stepforward(); 58 this.bigTurtle. turnRight900); this.bigTurtle Stepforward(); 60 this.bigTurtle. turnleft90(); ) 630 private void drawRectanglewithBigTurtle() { 64 this.bigTurtle.lowerTall(); 65 this.stepforward(this.bigTurtle, 12); 67 this.bigTurtle.turnRight9e(); 68 this.stepForward(this.bigTurtle, 6): this.bigTurtle. turnRight100); 59 61 62 66 69 70 Search Project Run Window Help eclipse-workspace - Project 1/src/edu/westgales 1301/project1/model/DoodleTurtle.java - Eclipse IDE 12 2 (14.0.211 14 15 16 17 18 19 controllers "DoodleTurtle.java > DoodleController.java 13 public class DoodleTurtle extends GTurtle { public static final double INITIAL_SPEED = 0.6; public static final int INITIAL_SIZE = 50; private int stepsForward; // TODO Part 1 6.1.a 20 21 220 23 Creates a new DoodleTurtle object of size 58 at location e, e. 24 25 precondition none @postcondition getTurtlesize() == INITIAL_SIZE 27 AND getLocation() -- (25, 25) AND getSpeed() - INITIAL_TURTLE_SPEED model utils 26 view 28 29 30 310 32 33 340 35 36 37 38 39 40 410 42 43 44 45 A public DoodleTurtle() { this.initializeWithdefaultValues(); public DoodleTurtlelint size) { this. Initializow4thDefaultValues(); this.setSize(*120): private void initializewithdefaultValues() { this.steps Forward = 0; this.setSize(INITIAL_SIZE); this.setSpeed (INITIAL_SPEED); this.setLocation (INITIAL_SIZE / 2. INITIAL_SIZE / 2); a. Modify the code by adding a parameter so that the turtle can turn left in any number of degrees: I. Refactor the turnLeft90 method so it is now named turnLeft. ii. Add a double parameter to this method that will represent the number of degrees to turn. ii. Modify the method body so that the call to this.left(90); replaces the literal value 90 with the name of the parameter. iv. Add and complete an @param tag to the method specification identifying the new parameter. v. Delete the turn Left30 method and its specification because we have the new turnLeft method. b. Compile the code and fix the compilations errors by calling the new turnLeft method. At this point the DoodleTurtle class should compile, but the DoodleController will not as the turnLeft90 and turnLeft30 methods no longer exist. For example, if there was a statement like the following: this little Turtle.turnleft300); it would now become this little Turtle.turn Left(30); i. If there are multiple consecutive calls to turn, refactor those to a single call. For example, two calls to turnleft901) would be one call to the new method passing in 180 as the argument. // TODO Part 1 B.1 /** * Turns the turtle 90 degrees to its left. * @precondition none * @postcondition none */ public void turnleft90() { turnleft(); } /**** 69 700 71 72 73 74 75 760 77 78 790 80 81 820 83 84 85 86 87 88 89 90 91 920 93 94 95 */ private void turnleft() { this. left(90); } * /** * Turns the turtle 30 degrees to its left. * @precondition none * @postcondition none */ public void turnLeft300) { this. left(30.0); } package edu.westga.cs1301.projecti.controllers; 30 import edu.vestga.cs1381.projecti.model.DoodleTurtle:( 5 60/ 7 8 9 10 11 / 14 Uses turtle objects to draw on the screen. Gauthor C51301 Oversion Spring 2021 12 public class DoodleController { 13 private DoodleTurtle big Turtle; private Doodleturtle littleTurtle; 15 160 17 Creates and initializes a new DoodleController object. eprecondition bigTurtle != null AND LittleTurtle != null epostcondition none 21 @param bigTurtle The turtle will be the bigger of the two turtles. @param littleTurtle The turtle will be the smaller of the two turtles. 27 public DoodleControllercadleTurtle bigturtle, Doodle Yurtle LittleTurtte) { 29 this.uttleTurtle - uttleTurtles 18 19 20 22 28 30 36 46 48 49 50 "DoodleTurtle.java DoodleController.java 350 /A Draws a figure on the screen using turtles. 37 3B precondition none 39 Opostcondition none 40 +/ 410 public void draw() { 42 // TODO Part 1.1 43 this. moveBigTurtleToPositionForFirstRectangle(); 44 this.drawRectanglewithBigTurtle(); this.noveLittleTurtleToPositionForFirstRectangle(); this.drawRectanglewithlittleTurtle(); this.noveBigTurtleTopositionForSecondRectangle(); this.drawfectangleWithBigTurtle(); this moveLittleTurtleToPositionForSecond Rectanglel): 53 this.drawRectanglewithlittleTurtle(): 54 } 55 566 private void moveBigTurtleTopositionForFirstRectangle() { 57 this.bigTurtle.stepforward(); 58 this.bigTurtle. turnRight900); this.bigTurtle Stepforward(); 60 this.bigTurtle. turnleft90(); ) 630 private void drawRectanglewithBigTurtle() { 64 this.bigTurtle.lowerTall(); 65 this.stepforward(this.bigTurtle, 12); 67 this.bigTurtle.turnRight9e(); 68 this.stepForward(this.bigTurtle, 6): this.bigTurtle. turnRight100); 59 61 62 66 69 70 Search Project Run Window Help eclipse-workspace - Project 1/src/edu/westgales 1301/project1/model/DoodleTurtle.java - Eclipse IDE 12 2 (14.0.211 14 15 16 17 18 19 controllers "DoodleTurtle.java > DoodleController.java 13 public class DoodleTurtle extends GTurtle { public static final double INITIAL_SPEED = 0.6; public static final int INITIAL_SIZE = 50; private int stepsForward; // TODO Part 1 6.1.a 20 21 220 23 Creates a new DoodleTurtle object of size 58 at location e, e. 24 25 precondition none @postcondition getTurtlesize() == INITIAL_SIZE 27 AND getLocation() -- (25, 25) AND getSpeed() - INITIAL_TURTLE_SPEED model utils 26 view 28 29 30 310 32 33 340 35 36 37 38 39 40 410 42 43 44 45 A public DoodleTurtle() { this.initializeWithdefaultValues(); public DoodleTurtlelint size) { this. Initializow4thDefaultValues(); this.setSize(*120): private void initializewithdefaultValues() { this.steps Forward = 0; this.setSize(INITIAL_SIZE); this.setSpeed (INITIAL_SPEED); this.setLocation (INITIAL_SIZE / 2. INITIAL_SIZE / 2)

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions