Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am using Eclipse for this. I have a paddle ball game written. What I really ne

ID: 641535 • Letter: I

Question

I am using Eclipse for this. I have a paddle ball game written. What I really need is an example of a paddle ball game that shows what the instructor is looking for with this.

Documentation

The objective of this part of the lab is to create documentation using Javadoc for the Paddle Ball Game project from week 5. The following documentation requirements must be met.

All commentary must use standard JavaDoc comments and tags.

For every class add a class level comment including the author and the purpose of the class.

Where one class heavily depends on the use of an object from another class, provide a link to the other class using the @see tag.

For every method, add a method level comment which includes information on the purpose of the method, the method parameters, and the result returned by the method.

Use the javadoc command to generate HTML files for your project.

Use the browser to view your generated documentation to verify that all the required information for all the classes is included.

Consult the document provided describing how to export JavaDoc comments from Eclipse.

When your documentation is complete, turn in one of the following depending on what your instructor requires:

            1. Print outs of all the documentation pages from the browser.

            2. A Zip file containing all the documentation pages.

Deployment

Create a JAR file for the Paddle Ball Game project from week 5. The JAR file must contain all the class files needed to make the Paddle Ball Game work. Consult the document provided describing how to export a JAR file from Eclipse. To test if you have made your JAR file correctly, double click on your JAR file using Windows Explorer. The Paddle Ball Game should start running. If you are on Citrix, you will need to copy your game to a local computer before you can successfully execute it.

When you have successfully executed your JAR file, turn in a copy of your JAR file to your instructor.

Explanation / Answer

// PB_Ball Class File
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PB_Ball
{
int x, y;
// Position of the upper left corner of containing box
int Xincrement;
// Amount to move left or right
int Yincrement; // Amount to move up or down
int size;
// Diameter of the ball
public PB_Ball(int diameter, int distance)
{
size = diameter;
Xincrement = Yincrement = distance;
x = y = 10;
// Initial ball position
}

public void updatePos(int width, int height)
{
// Add increment to current position
x += Xincrement;
y += Yincrement;
// Check if we have hit a wall!
// Left wall at 0, right wall at width
// Top wall at 0, bottom wall at height
// Reverse the sign of the increment if we have.
if ((x <= -3)||(x + size >= width + 3))
Xincrement = -Xincrement;
if ((y <= -3)||(y + size >= height + 3))
Yincrement = -Yincrement;
}
public void reverseHorizontalDirection()
{
Xincrement = -Xincrement;
}
public void reverseVerticalDirection()
{
Yincrement = -Yincrement;
}
public int getTop()
{
// Return position of top of ball
return y;
}
public int getBottom()
{
// Return position of bottom of ball
return y + size;
}
public int getLeft()
{
// Return position of left edge of ball
return x;
}
public int getRight()
{
// Return position of right edge of ball
return x + size;
}
public int getHorizontalCenter()
{
// Return the horizontal center of the ball
return x + size/2;
}
public int getVerticalCenter()
{
// Return the vertical center of the ball
return y + size/2;
}
public void drawBall(Graphics g)
{
g.setColor(Color.green);
g.fillOval(x, y, size, size);
}
}
// PB_Paddle Class File
import java.awt.*;
public class PB_Paddle
{
private static final int WIDTH = 5;
private int length;
private int xpos, ypos;

// length of the paddle
// if horizontal, position of center of the top paddle surface

// if vertical, position of the center of the left paddle

surface
public PB_Paddle(int length, int x, int y)
{
this.length = length;
xpos = x;
ypos = y;
}
public void updatePos(int x, int y)
{
// Can only move left or right
xpos = x;
}

public int getLeft()
{
// Return the left surface position of the paddle
return xpos - length / 2;
}
public int getRight()
{
// Return the right surface position of the paddle
return xpos + length / 2;
}
public int getTop()
{
// Return the top surface position of the paddle
return ypos;
}
public int getBottom()
{
// Return the bottom surface position of the paddle
return ypos + WIDTH;
}
public void drawPaddle(Graphics g)
{
// The mouse cursor represents the center of the paddle
g.setColor(Color.red);
g.fillRect(xpos - length/2, ypos, length, WIDTH);
}
}
// PaddleBallGUI Class File
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PaddleBallGUI extends JPanel
{
PaddleBallController controller;
JFrame frame;
PaddleBallGUI(PaddleBallController gameController)
{
// Store the game controller
controller = gameController;
// Create a frame and place the panel into it
frame = new JFrame();
frame.add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setVisible(true);
}
public void paintComponent(Graphics g)
{
// Erase what is currently in the display area
g.setColor(Color.cyan);
g.fillRect(0, 0, getWidth(), getHeight());
// Let the game controller update the display
controller.drawGame(g);
}

}
// PaddleBallController Class File
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
public class PaddleBallController implements ActionListener, MouseMotionListener
{
private final static int DIAMETER = 30;
// Ball diameter
private final static int INCREMENT = 8;
// Ball travel distance per event
private final static int LENGTH = 75; // Paddle length
private PB_Ball game_ball;
private PB_Paddle game_paddle;
private PaddleBallGUI game_display;
private Timer timerObj;

// Timer will create events to move the ball

public PaddleBallController()
{
game_display = new PaddleBallGUI(this);// Display calls controller's drawGame method
game_ball = new PB_Ball(DIAMETER, INCREMENT);
// Create paddle based on initial display area size
game_paddle = new PB_Paddle(LENGTH, game_display.getWidth()/2, game_display.getHeight()/10);
// Now set up the events that drive the game
timerObj = new Timer(25, this); // Create a timer which fires every 25 milliseconds
timerObj.setInitialDelay(1000); // Have the timer wait 1 second before firing the first time
timerObj.start(); // Start the timer running
// Initialize the mouse event handler
game_display.addMouseMotionListener(this);
}
public void drawGame(Graphics g)
{
if(game_ball != null)
game_ball.drawBall(g);
if(game_paddle != null)
game_paddle.drawPaddle(g);
}
public void actionPerformed(ActionEvent e)
{
// Ball moves within size of the display area
game_ball.updatePos(game_display.getWidth(), game_display.getHeight());
// Determine if the ball is in contact with the paddle
int btop = game_ball.getTop();
int pbottom = game_paddle.getBottom();
// Is the top of the ball now in contact with the paddle?
if(btop <= pbottom && btop >= pbottom - INCREMENT)
{
// Is the center of the ball within left and right edge of the paddle?
int bcenter = game_ball.getHorizontalCenter();
if(bcenter >= game_paddle.getLeft() && bcenter <= game_paddle.getRight())
{
// Reverse the vertical travel direction of the ball
game_ball.reverseVerticalDirection();
}
}
// Cause the GUI to redraw itself.
game_display.repaint();
}
public void mouseDragged(MouseEvent mouseEvnt)
{
int x, y;
// The mouse has moved, so get cursor position
x = mouseEvnt.getX();
y = mouseEvnt.getY();
// Update the position of the paddle and tell the GUI to redraw
game_paddle.updatePos(x, y);
game_display.repaint();
}
public void mouseMoved(MouseEvent mouseEvnt)
{
int x, y;
// The mouse has moved, so get the cursor position

}

x = mouseEvnt.getX();
y = mouseEvnt.getY();
// Update the position of the paddle and tell the GUI to redraw
game_paddle.updatePos(x, y);
game_display.repaint();

}
// StartGame Class File
public class StartGame
{
public static void main(String[] args)
{
PaddleBallController game = new PaddleBallController();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote