Religious Studies > SOPHIA Milestone > College of William & Mary - CS 1114 Turtle.java. (All)
import sofia.micro.*; import sofia.util.Random; */ public class Turtle extends Actor { //~ Fields ................................................................ //~ Constructor ............... ... ............................................ // ---------------------------------------------------------- /** * Creates a new Turtle object. */ public Turtle() { /*# Do any work to initialize your class here. */ } //~ Methods ............................................................... /** * a method to randomly turn right or left. */ public void randomTurn() { if (Random.generator().nextBoolean()) { turn(90); } else { turn(-90); } } /** * a method to add a marker whereever there is a turtle. */ public void move() { Marker marker1 = new Marker(); this.getWorld().add(marker1, this.getGridX(), this.getGridY()); super.move(1); if (this.getOneIntersectingObject(Marker.class) == null) { Marker marker = new Marker(); this.getWorld().add(marker, this.getGridX(), this.getGridY()); } } /** * makes the marker move num times. * @param num is a random number that I may choose. */ public void move(int num) { for (int i = 0; i < num; i++) https://www.coursehero.com/file/57231140/Turtlejava/ This study resource was shared via CourseHero.com{ move(); } } public void act() { int i = Random.generator().nextInt(4) + 1; move(i); randomTurn(); [Show More]
Last updated: 3 years ago
Preview 1 out of 2 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Mar 20, 2021
Number of pages
2
Written in
All
This document has been written for:
Uploaded
Mar 20, 2021
Downloads
0
Views
126
Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·