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
Ballclass now has acolorinstance variable.coloris a Processing-specific primitive variable type that can be assigned using thecolor(r, g, b)function or using color hexcode values.color c = color(193, 20, 231);orcolor 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
xspeedandyspeedfields to be either1or-1, chosen randomly. - The second constructor should set the
csizeto a random value in the range[10, 100)instead of taking a parameter for the size; displayshould appropriately display the color of theBallobject.- When a
Ballobject hits a wall, the corresponding speed field (xspeedfor horizontal walls andyspeedfor vertical walls) should increase in magnitude by1. That means that if the speed is-1, it should increase to-2.
