Posted: Mon Nov 2

Due: Tuesday 11/3 10:00am

Submission name: w19_balls

Update the Ball class:

You will make a Ball class that should match the following UML diagram:

classDiagram class Ball { -int cx -int cy -int csize -int xspeed -int yspeed -color inside +Ball(int x, int y, int xs, int ys, int cs, color c) +Ball(int maxX, int maxY) +void display() -boolean hitHorizonatalWall(int left, int right) -boolean hitVerticalWall(int top, int bottom) +move(int left, int right, int top, int bottom) }

Changes from the previous work:

  • The Ball class now has a color instance variable.
    • color is a Processing-specific primitive variable type that can be assigned using the color(r, g, b) function or using color hexcode values.
    • color c = color(193, 20, 231); or color c = #F3A2C4; are valid. You can use Processing’s built in color picker tool to explore color values.
  • The first constructor now has a parameter representing the color.
  • The second constructor should set the inside as you see fit (this could be a random color or the same color).
  • The second constructor should set the xspeed and yspeed fields to be either 1 or -1, chosen randomly.
  • The second constructor should set the csize to a random value in the range [10, 100) instead of taking a parameter for the size;
  • display should appropriately display the color of the Ball object.
  • When a Ball object hits a wall, the corresponding speed field (xspeed for horizontal walls and yspeed for vertical walls) should increase in magnitude by 1. That means that if the speed is -1, it should increase to -2.

a19_balls