Hello. Please help me complete the code. A picture of the problem statement has been provided, as well as  the code to be completed and the driver code.  Please make sure the test cases are passed.    /**    This class models a ball that bounces off walls. */ public class Ball {

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello. Please help me complete the code. A picture of the problem statement has been provided, as well as 

the code to be completed and the driver code. 

Please make sure the test cases are passed. 

 

/**
   This class models a ball that bounces off walls.
*/
public class Ball
{
   // Instance variables
   /* Your code goes here */
   /**
      Constructs a ball at (0, 0) traveling northeast.
      @param rightWall the position of the wall to the right
      @param topWall the position of the wall at the top
   */
   public Ball(int rightWall, int topWall)   
   {
      /* Your code goes here */
   }
 
   /**
      Moves the ball.
   */
   public void move()
   {
      /* Your code goes here */
   }
 
   /**
      Turns the ball direction 90 degrees clockwise.
   */
   private void turn()
   {
      /* Your code goes here */
   }
 
   /**
      Gets the current x-position.
      @return the x-position
   */
   public int getX()
   {
      /* Your code goes here */
   }
 
   /**
      Gets the current y-position.
      @return the y-position
   */
   public int getY()
   {
      /* Your code goes here */
   }
}

 

 

public class BallTester
{
   public static void main(String[] args)
   {
      Ball ball1 = new Ball(6, 4);
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 0 0");
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 1 1");
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 2 2");
      ball1.move();
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 4 4");
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 5 3");
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 6 2");
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 5 1");
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 4 0");
      ball1.move();
      System.out.println(ball1.getX() + " " + ball1.getY());
      System.out.println("Expected: 3 1");


      Ball ball2 = new Ball(10, 10);
      for (int i = 1; i <= 12; i++) { ball2.move(); }
      System.out.println(ball2.getX() + " " + ball2.getY());
      System.out.println("Expected: 8 8");
   }
}

 

 

 

 

A ball bounces inside a given rectangle, starting at the rectangle's bottom left corner at (0, 0) and initially moving in the northeast
direction. When the ball bounces on a wall, it turns 90 degrees clockwise. If it bounces on a corner, its direction reverses. The
move method advances its position by one unit in the (x)-direction (left or right) and one unit in the (y)-direction (up or down).
Transcribed Image Text:A ball bounces inside a given rectangle, starting at the rectangle's bottom left corner at (0, 0) and initially moving in the northeast direction. When the ball bounces on a wall, it turns 90 degrees clockwise. If it bounces on a corner, its direction reverses. The move method advances its position by one unit in the (x)-direction (left or right) and one unit in the (y)-direction (up or down).
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education