
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Implement all the classes using Java
Note: This problem requires you to submit only one class: Ball.java.
Do NOT include "public static void main()" method inside all of these classes. Graders will be testing your classes, using the unit-testing framework JUnit 4.
A class called Ball is designed as shown in the class diagram.
The Ball class contains the following private instance variables:
- x, y and radius, which represent the ball's center (x, y) co-ordinates and the radius, respectively.
- xDelta (Δx) and yDelta (Δy), which represent the displacement (movement) per step, in the x and y direction respectively.
The Ball class contains the following public methods:
- A constructor which accepts x, y, radius, speed, and direction as arguments. For user friendliness, user specifies speed (in pixels per step) and direction (in degrees in the range of (-180°, 180°]). For the internal operations, the speed and direction are to be converted to (Δx, Δy) in the internal representation. Note that the y-axis of the Java graphics coordinate system is inverted, i.e., the origin (0, 0) is located at the top-left corner.
- Δx = d × cos(θ) Δy = -d × sin(θ)
Hint: You will find Math.cos() and Math.toRadians(direction) static methods usefull. Don't forget that "d" is a speed.
- Getter and setter for all the instance variables.
- A method move() which move the ball by one step. x += Δx y += Δy
- reflectHorizontal() which reflects the ball horizontally (i.e., hitting a vertical wall) Δx = -Δx Δy no changes
- reflectVertical() (the ball hits a horizontal wall).Δx no changes Δy = -Δy
- toString() which prints the message "Ball at (x, y) of velocity (Δx, Δy)".
Write and submit the Ball class.

Transcribed Image Text:Ax
d (speed)
O (direction)
Ay
User's Polar
Java Graphics
Co-ordinates system
Co-ordinates
![Ball
-x:float
-y:float
-radius:int
Each move step advances x and y
by Ax and Ay. Ax and Ay could be
positive or negative.
|-xDelta:float
-yDelta:float
+Ball(x:float,y:float,radius:int
speed:int, direction:int)
+getX():float
+setX(x:float):void
+getY():float
+setY(y:float):void
+getRadius ():int
+setRadius (radius:int):void
+getXDelta():float
+setXDelta(xDelta:float):void
+getYDelta():float
+setYDelta(yDelta:float):void
+move ():void•-
+reflectHorizontal():voide
+reflectVertical():void•
+toString():String
Move one step:
х +3 Дх; у +3D Ду;
Ax = -Ax
Ay = -Ay
"Ball[(x,y),speed%-D(Ax,Ay)]"](https://content.bartleby.com/qna-images/question/f3dad014-c6bb-4735-812f-053559c6a885/8d80b90b-1361-49cd-81b0-9d65b1ebc209/jpq118q_thumbnail.png)
Transcribed Image Text:Ball
-x:float
-y:float
-radius:int
Each move step advances x and y
by Ax and Ay. Ax and Ay could be
positive or negative.
|-xDelta:float
-yDelta:float
+Ball(x:float,y:float,radius:int
speed:int, direction:int)
+getX():float
+setX(x:float):void
+getY():float
+setY(y:float):void
+getRadius ():int
+setRadius (radius:int):void
+getXDelta():float
+setXDelta(xDelta:float):void
+getYDelta():float
+setYDelta(yDelta:float):void
+move ():void•-
+reflectHorizontal():voide
+reflectVertical():void•
+toString():String
Move one step:
х +3 Дх; у +3D Ду;
Ax = -Ax
Ay = -Ay
"Ball[(x,y),speed%-D(Ax,Ay)]"
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
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
- All vehicles used for transportation in the U.S. must have identification, which varies according to the type of vehicle. For example, all automobiles have a unique Vehicle Identification Number (VIN) assigned by the manufacturer, plus a license plate number assigend by the state in which the auto is registerd. Modify the Auto class to include an instance variable for the license plate number. Implement the constructor so that an Auto can be constructed with a VIN and a license plate number. Override the getID() method to return the id of the auto as shown in this format: VIN=1234567890,plate=ABC123 (without any spaces). ** Represents an automobile.*/public class Auto // TODO: Inherit from Vehicle{ // TODO: Declare instance variables public Auto(String vin, String plate) { // TODO: Complete the constructor } // TODO: implement the getID() method for autos}arrow_forwardAfter drawing the hierarchy, implement the classes by writing C# code foreach class. Then create objects of each class and call ALL methods onthese objects.arrow_forwardFor this exercise, you will be completing the Account class, which simulates a regular bank account, then using overrides and calls to the superclass to create a StudentAccount. Student accounts differ from regular accounts in that they get a bonus $1 for every deposit, but a $2 fee for every withdrawal. You will override the methods in the StudentAccount by calling the superclass methods with the additonal amount or fee incorporated since the balance is not directly stored in the StudentAccount object. You will also update the toString, as outlined in the comments. When completed, create one student account and one regular account for testing. Deposit and withdraw money and print the results. import java.text.*;public class BankTester{public static void main(String[] args){Account a = new Account("Imran", 1100);a.deposit(200.00);System.out.println(acc1.toString());a.withdraw(100.00); }} public class StudentAccount extends Account{// Complete this class with Override methods.…arrow_forward
- Choose necessary patters, draw the UML and code just company class methods on paper. A car company makes a car produce application. There are diffrerent types of models that the company builds as sedan and sport. Each model has some shared and distinguishing features. The object creation process should conduct by a central class. The second central class should not be created in the application.arrow_forwardComplete the FoodItem class by adding a constructor to initialize a food item. The constructor should initialize the name to "None" and all other instance attributes to 0.0 by default. If the constructor is called with a food name, grams of fat, grams of carbohydrates, and grams of protein, the constructor should assign each instance attribute with the appropriate parameter value. The given program accepts as input a food item name, fat, carbs, and protein and the number of servings. The program creates a food item using the constructor parameters' default values and a food item using the input values. The program outputs the nutritional information and calories per serving for both food items. Ex: If the input is: M&M's 10.0 34.0 2.0 1.0 where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 1.0 is the number of servings, the output is: Nutritional information per serving of None: Fat: 0.00 g Carbohydrates:…arrow_forwardBelow for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forward
- In Python 3, write a program with classes to keep track of phones. Here are the requirements: Create a new class called Phone. The Phone class should have a class attribute for the owner's name. Since all phones have a manufacturer and a model number, your class should take the manufacturer and model number from the constructor and assign them to instance attributes. Your Phone constructor should be able to take the parameters. Override the print method for Phone to output a human-friendly version of the information. Your code should prompt the user for an owner name and then start prompting for the manufacturers and models for all phones for that user until the user enters a 'q' or 'Q'. After the entry print out a list of all the phones.arrow_forwardUse the class diagram below to create a Parking Charge class for an object-oriented parking system. Write your code using java. Classes should contain properties and method implementations. N.B. Try to make your code readable.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education