Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 27th, 2014  |  syntax: None  |  size: 1.40 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. public class FleetOfDyads
  3. BEGIN
  4.     Dyad[] fleetMembers // declare fleetMembers as an array of Ball
  5.     integer total = 5 // Max number of squares in fleet
  6.  
  7.     FleetOfDyads() // Constructor
  8.     BEGIN
  9.         fleetMembers = new Dyad[total] // create an empty array with 5 "locations"
  10.         FOR (integer i = 0, i < total, i = i + 1) // loop: carry on whilst i is less than 5, add 1 each cycle
  11.             fleetMembers[i] = new Dyad()  // create a Ball object for location [i] in the array
  12.             fleetMembers[i].setX (i * 10) // multiply i by 10, and pass this to the setX method
  13.             fleetMembers[i].setY (i * 10) // multiply i by 10, and pass this to the setY method
  14.         END-FOR
  15.     END
  16.    
  17.     public void draw()
  18.     BEGIN
  19.         FOR (integer i = 0, i < total, i = i + 1) // loop: carry on whilst i is less than 5, add 1 each cycle
  20.             fleetMembers[i].draw()    // ask fleetMember[i] to draw itself
  21.         END-FOR
  22.     END
  23.    
  24.     public void goSouth(integer howFar)
  25.     BEGIN
  26.         FOR (integer i = 0 i < total i = i + 1) // loop: carry on whilst i is less than 5, add 1 each cycle
  27.             // ask fleetMember[i] for its current Y position
  28.             // then add howFar (howFar to go south) to it
  29.             // then pass this to the setY method
  30.             fleetMembers[i].setY (fleetMembers[i].getY() + howFar)
  31.         END-FOR
  32.     END  
  33. END // end of class