fosterbl

Ball

Feb 25th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. class Ball extends Block{
  2.   private int xSpeed;
  3.   private int ySpeed;
  4.  
  5.   public Ball() {
  6.     super(200, 200,10,10);
  7.     xSpeed = 3;
  8.     ySpeed = 1;
  9.   }
  10.  
  11.   //add other Ball constructors
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.   //mutator methods for x and y speed
  26.  
  27.  
  28.   public void moveAndDisplay(){
  29.     //draw a white ball at old ball location using inherited display(color col) method
  30.    
  31.     setX(getX()+xSpeed);
  32.     //setY too
  33.  
  34.     //draw ball at new location
  35.     //using inherited display() method
  36.   }
  37.  
  38.  
  39.   //equals method
  40.   //should call Block’s equals method
  41.   //and also check x and y speed
  42.  
  43.   //accessor methods for speed
  44.  
  45.  
  46.   public String toString() {
  47.     //should call Block’s toString
  48.     //and also add x and y speed
  49.   }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment