Programming > STUDY GUIDE > Virginia Tech - CS 1114Marble.java (All)
import sofia.micro.*; import java.util.List; import java.util.ArrayList; //------------------------------------------------------------------------- /** * This is the marble class * * @author E... mily Ashburn (emily2000) * @version (2019.04.04) */ public class Marble extends Actor { //~ Fields ................................................................ private Marble melvin; //~ Constructor ........................................................... // ---------------------------------------------------------- /** * Creates a new Marble object. */ public Marble() { // Do NOT try to calculate the list of friends here, // the marble is not added to a world yet, so it has // no neighbors. } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Finds the marble at the specified height (which could be * at any x-coordinate for that height). * @param yPosition The y-coordinate where the marble is located. * @return The marble with the specified y-coordinate. */ public Marble getMarbleAtHeight(int yPosition) { for (int i = 0; i < this.getWorld().getWidth(); i++) { melvin = this.getWorld().getOneObjectAt(i, yPosition, Marble.class); if (melvin != null) { return melvin; } } return null; } // ---------------------------------------------------------- /** * Get a list of the marbles within two rows on either side * of this marble, not including this marble itself. * @return A list of the marbles with y-coordinates 1 or 2 * cells above or below this marble, not including * this marble. */ public List<Marble> getFriends() { List<Marble> marbleList = new ArrayList<Marble>(); for (int j = this.getGridY() - 2; j <= this.getGridY() + 2; j++) { [Show More]
Last updated: 1 year ago
Preview 1 out of 2 pages
Instant download
Buy this document to get the full access instantly
Instant Download Access after purchase
Add to cartInstant download
Connected school, study & course
About the document
Uploaded On
Mar 24, 2021
Number of pages
2
Written in
This document has been written for:
Uploaded
Mar 24, 2021
Downloads
0
Views
100
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·