Bouncing Ball
*********
*********
 Due Date: Friday September 29, 2023
Instructions: We will build a bouncing Ball.

Be sure to replace lastname with your lastname.

Your files name will be PX_BouncingBall_lastname
File P5_BouncingBall_lastname.java (The actual java code)
File P5_BouncingBall_lastname.png (Screen print of java code inside the IDE)
File P5_BouncingBall_lastname.mp4 (Screen recording of this animation running.)

Hints: Look at your last simple animation.
Review all part below for clues.

Below are:
1. a description of your programs.
2. Pseudo Code for you java program.
3. The solution sorted.


Be sure to drop them off into Google Classroom.

*********
*********
 Due Date: Friday September 29, 2023
Instructions: Read the Specification below:

## Bouncing Ball Animation Program Specification

### 1. Introduction

The Bouncing Ball Animation program is a Java
application that creates an animated graphical 
representation of a bouncing ball within a window.
This document outlines the functionality, 
user interaction, and technical details of the program.

### 2. Program Features

#### 2.1. Ball Animation

- The program displays a window containing a 
red ball that moves within the boundaries of the window.
- The ball continuously bounces off the edges
of the window, creating a bouncing animation.

#### 2.2. Customization

- The initial position, size, and speed of 
the ball are customizable through variables within the code.
- Users can modify the appearance of the ball, 
such as its color and shape, by changing the code.

### 3. User Interaction

- The program does not include a graphical 
user interface (GUI) for user interaction.
- Customization of the ball's properties 
requires manual modification of variables
within the Java source code.

### 4. Technical Details

#### 4.1. Programming Language

- The program is written in Java, making
use of the Java Swing library for graphical rendering.

#### 4.2. Animation Logic

- Animation is achieved using a timer that
triggers the update of the ball's position
at regular intervals (10 milliseconds by default).
- The ball's position is updated according 
to its speed and direction, and collisions 
with the window edges are detected and handled.

#### 4.3. Customization

- Customization of the ball's properties 
(e.g., initial position, size, and speed) 
is done by modifying the relevant variables in the Java source code.
- Users can change the appearance of the 
ball (e.g., color) by modifying the code that defines its rendering.

### 5. System Requirements

- Java Development Kit (JDK) 8 or later 
installed on the system.
- A Java Integrated Development 
Environment (IDE) or text editor 
to view and edit the source code.
- Sufficient system resources to 
run a graphical application.

### 6. Usage

1. Open the Java source code file in 
a Java development environment.
2. Customize the program by modifying
the relevant variables in the code.
3. Compile and run the program.
4. A window displaying the bouncing
ball animation will appear.

### 7. Limitations

- The program does not provide a
user-friendly interface for customizing 
the ball's properties, requiring 
manual code modification.
- The program is intended for educational
purposes and may not have extensive features or advanced graphical capabilities.

### 8. Conclusion

The Bouncing Ball Animation program is
a simple Java application that demonstrates 
basic animation and graphical rendering techniques.
Users can customize the animation's 
characteristics by modifying the code, 
making it a useful educational tool for
learning Java programming and graphics.

---

*********
*********
 Due Date: Friday September 29, 2023
Instructions: Read and study the Pseudo Code below:
// Define constants for the window dimensions and ball properties
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 400
BALL_DIAMETER = 50
BALL_COLOR = RED
BALL_INITIAL_X = 50
BALL_INITIAL_Y = 50
BALL_SPEED_X = 2
BALL_SPEED_Y = 2

// Initialize the ball's position
ballX = BALL_INITIAL_X
ballY = BALL_INITIAL_Y

// Create a timer to update the animation every 10 milliseconds
CREATE_TIMER(interval: 10, callback: updateAnimation)

// Function to update the animation
FUNCTION updateAnimation()
    // Update the ball's position based on its speed and direction
    ballX = ballX + BALL_SPEED_X
    ballY = ballY + BALL_SPEED_Y

    // Detect collisions with the window edges
    IF ballX <= 0 OR ballX >= WINDOW_WIDTH - BALL_DIAMETER
        // Reverse the horizontal direction
        BALL_SPEED_X = -BALL_SPEED_X
    END IF

    IF ballY <= 0 OR ballY >= WINDOW_HEIGHT - BALL_DIAMETER
        // Reverse the vertical direction
        BALL_SPEED_Y = -BALL_SPEED_Y
    END IF

    // Redraw the window to show the updated position of the ball
    DRAW_WINDOW()

END FUNCTION

// Function to draw the window and the ball
FUNCTION DRAW_WINDOW()
    // Clear the window
    CLEAR_WINDOW()

    // Draw the ball at its current position
    DRAW_CIRCLE(color: BALL_COLOR, x: ballX, y: ballY, diameter: BALL_DIAMETER)

    // Display the updated window
    SHOW_WINDOW()
END FUNCTION

// Main program
FUNCTION MAIN()
    // Create a window with dimensions WINDOW_WIDTH x WINDOW_HEIGHT
    CREATE_WINDOW(width: WINDOW_WIDTH, 
	height: WINDOW_HEIGHT, title: "Bouncing Ball Animation")

    // Start the animation timer
    START_TIMER()

    // Enter the event loop to handle user
	interactions and animation updates
    WHILE true
        HANDLE_EVENTS()
    END WHILE

END FUNCTION

// Start the main program
MAIN()

*********
*********
 Due Date: Friday September 29, 2023
Instructions: Read the solution below after being Sorted:
            ballSpeedX = -ballSpeedX; // Reverse horizontal direction
            ballSpeedY = -ballSpeedY; // Reverse vertical direction
        // Detect collisions with the edges of the panel
        // Draw the ball
        // Repaint the panel to show the updated position
        // Set up a timer to update the animation
        // Update the position of the ball
        }
        }
        ballX += ballSpeedX;
        ballY += ballSpeedY;
        frame.add(animation);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        frame.setVisible(true);
        g.fillOval(ballX, ballY, ballDiameter, ballDiameter);
        g.setColor(Color.RED);
        if (ballX <= 0 || ballX >= getWidth() - ballDiameter) {
        if (ballY <= 0 || ballY >= getHeight() - ballDiameter) {
        JFrame frame = new JFrame("Bouncing Ball Animation");
        P5_bouncingBall_Cusack animation = new P5_bouncingBall_Cusack();
        repaint();
        super.paintComponent(g);
        Timer timer = new Timer(10, this);
        timer.start();
    @Override
    @Override
    }
    }
    }
    }
    private int ballDiameter = 50;  // Diameter of the ball
    private int ballSpeedX = 2;  // Horizontal speed of the ball
    private int ballSpeedY = 2;  // Vertical speed of the ball
    private int ballX = 50;  // Initial X position of the ball
    private int ballY = 50;  // Initial Y position of the ball
    protected void paintComponent(Graphics g) {
    public P5_bouncingBall_Cusack() {
    public static void main(String[] args) {
    public void actionPerformed(ActionEvent e) {
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
package APCS_A;
public class P5_bouncingBall_Cusack extends JPanel implements ActionListener {