Hi, I think I'm missing part of my assignment please help fix Assignment given: For this assignment you will create a bo

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Hi, I think I'm missing part of my assignment please help fix Assignment given: For this assignment you will create a bo

Post by answerhappygod »

Hi, I think I'm missing part of my assignment please help
fix
Assignment given:
For this assignment you will create a bouncing balls animation
(very similar to the BouncingBall.java sample program). To
complete the assignment you will complete and submit two files:
1) Ball.java - this file will contain a class that defines the
attributes and methods for a single Ball object that can be drawn
in the animation program
2) BouncingBalls.java - this file will contain the main program
that draws the animation of the Ball objects in an infinite
loop
Requirements for Ball.java:
+ constructor method that sets the initial position of the
center to the coordinates (0,0) in the window (Note: we are
assuming a window that ranges from -1 to 1 in both the x and y
direction) and sets the velocity, radius, and color to random
values. You can decide on a reasonable range for these random
values, but remember that the window only ranges from -1 to 1, so
the values need to be small enough for the Ball to fit in the
window and not move too "fast" (try values <0.1 for the radius
and <0.03 for the velocity components). You can also
decide on which colors to pick from, but your code should select
from at least three different colors randomly for the color of the
Ball.

+ "getter" and "setter" methods that allow retrieving and changing
the Ball objects center coordinates and velocity components.
all together, there should be 8 of these methods in total.
Note: IntelliJ can automatically generate these methods for
you.

+ "getter" methods that return the radius and color of the Ball
object.
Requirements for BouncingBalls.java:
+ using the given file, complete the program to draw the
animation

+ to start, the program should have one Ball added to an ArrayList
of Ball objects that is created and drawn to bounce around the
window. when the ball "hits" one of the sides, it should
reflect and continue moving, as in the BouncingBall sample
program

+ if the user presses the mouse button anywhere on the window (use
StdDraw.isMousePressed() to check for this in the animation loop),
generate a new Ball and add it to your ArrayList. thus, the
loop should draw every Ball object in the ArrayList every time
through the loop. if the user keeps pressing the mouse
button, more and more Ball objects should be created, added to the
ArrayList and drawn in the window to bounce around. note:
it's ok if a bunch of balls get added with a single mouse press (a
single press actually will be registered multiple times if you put
it in a loop because of the speed of the program execution)
Code:
I think I'm supposed to add to the ball.java code but it runs
fine so what do I add?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply