Question: what is the code for below program Task 1 : The PongBall Class: Description: The PongBall class describes the object which the Pong application

what is the code for below program " Task 1: The PongBall Class:
Description:
The PongBall class describes the object which the Pong application uses to represent the ball that bounces around the screen. The following class diagram illustrates the information and operations that are defined by the PongBall class.
In the first row of the below diagram, you will see the list of instance variables. In the second row, you will see how your constructor should look and in the last row, you will see the list of methods signatures that you need to define and implement.
PongBall Class Diagram:
class: PongBall
Instance variables: x, y, xVelocity, yVelocity
Constructor: PongBall(int initX, int initY, int initXVel, int initYVel)
Methods:
void bounceX()
void bounceY()
int getX()
int getY()
void move()
When the Pong application is executed it creates a new PongBall object that is positioned at the center of the playing field. Approximately every 10th of a second the Pong application calls the move() method on its PongBall object causing the ball to update its position. Following the call to move() the Pong application uses the getX() and getY() methods to find the new location of the ball. If the Pong application determines that the ball would have collided with a wall or a paddle, it will invoke the bounceX() or the bounceY() method to change the horizontal or vertical direction of the ball. Finally, the Pong application will draw the ball on the screen at its new location and the process will be repeated again in another 10th of a second.
Implementation:
Save the PongBall class in the file PongBall.java in your /CIS36A/Pong directory.
To implement the PongBall class you will need to define instance data for the x and y position of the ball as well as the velocity of the ball in the x and y directions. Additional information about the constructors and instance methods of the PongBall class can be found in the Java Documentation for the PongBall class Links to an external site.. Your implementation of the PongBall class must meet the specifications given in the Java Documentation (also above diagram), so please study it carefully.
To compile the java class, use this command: javac PongBall.java
Compiling PongBall.java will create PongBall.class and this will overwrite the existing class file.
Do not directly run this class because it does not have a main method to run.
Testing:
One way to test the PongBall class would be to run the Pong application and see if the ball begins moving correctly. However, because we do not know precisely how the Pong application uses the PongBall class, it would be very difficult to determine simply by watching the Pong application if the PongBall class behaves correctly in every situation. Thus, before testing the PongBall class with the Pong application we will test its behavior independently.
To test the PongBall class you will need to write a class named PongBallTest that contains a main method. The main method in the PongBallTest class should create several PongBall objects and test their instance methods. For example, the following snippet of code will create a PongBall object and test the getX(), getY() and move() methods:
public class PongBallTest {
public static void main(String[] args){
PongBall ball = new PongBall(10,20,2,4);
System.out.println("x should be 10, x is: "+ ball.getX());
System.out.println("y should be 20, y is: "+ ball.getY());
ball.move();
System.out.println("x should be 12, x is: "+ ball.getX());
System.out.println("y should be 24, y is: "+ ball.getY());
ball.move();
System.out.println("x should be 14, x is: "+ ball.getX());
System.out.println("y should be 28, y is: "+ ball.getY());
}
}
Notice that the output of the test program indicates both the correct values and the actual values that are computed. Writing your test programs in this way makes it easy to tell if the class you are testing is working correctly.
You will need to add additional code to the PongBallTest class to test the bounceX() and bounceY() methods.
Integration:
Once you have fully tested your PongBall class, you can integrate it into the Pong application:
Now when you execute the instruction java Pong & the Pong application will run using your PongBall class. When the Pong window appears, press the "B" key on the keyboard and the ball should begin bouncing around the playing field."

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!