Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 (60%] You are required to build a Circle class to define the blueprint of circles. The primitive properties about a certain circle include

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Question 1 (60%] You are required to build a Circle class to define the blueprint of circles. The primitive properties about a certain circle include x, y, and r, which define the x, y position (coordinate) of the center of the circle and r defines its radius. A Circle class is defined as follows public class Circle { private double x; private double y; private double r; public Circle(double x, double y, double r) { } public void setPosition (double x, double y) { } public void setRadius (double r) { } public double getPositionx() { } public double getPositionY() { } public double getRadius() { } public double getArea() { } public boolean isCollidedWith(Circle c) { } } You need to implement 8 methods for the Circle class, namely Circle(), set Position(), setRadius(), getPositionX(), getPosition y(), getRadius(), getArea() and isCollidedWith(). You are NOT allowed to make change to the parameters list and return type. Part 1: Implement the constructor and get methods . 1. Circle() is the constructor of the class. This function is called when creating a Circle object. Parameters: X-(double): define the position x of the new circle object. y-(double): define the position y of the new circle object. r-(double): define the radius of the new circle object. . 2. getPositionX() returns the x position of this circle object. Return (double): return the x position of this circle. 3. getPositionY() returns the y position of this circle object. Return (double): return the y position of this circle. 4. getRadius() returns the radius of this circle object. Return (double): return the radius of this circle. 5.getArea() returns the area of this circle. Area (A) is defined as A = r rwhere r is the radius. You may make use of Math.PI in Java to get the value of n. Return (double): return the area of this circle. Sample main() public static void main(String[] args) { Circle c1 = new Circle(10, 10, 3); System.out.println("Reporting c1:"); System.out.println("x: " + c1.getPositionx()); System.out.println("y: " + c1.getPositionY()); System.out.println("r: " + c1.getRadius()); System.out.println("Area: + c1.getArea()); Sample output Reporting c1: X: 10.0 y: 10.0 r: 3.0 Area: 28.274333882308138 6. setPosition() sets the new position for this circle. Both the x and y position should be specified when setting a new position. Parameters: x-(double): define the new position x for this circle object. y-(double): define the new position y for this circle object. 7. setRadius() sets the new radius for this circle. Parameter r-(double): define the new value of radius for this circle object . Sample main() public static void main(String[] args) { Circle c1 = new Circle(10, 10, 3); System.out.println("Setting new position and radius for cl... "); c1.setPosition (20, 20); c1.setRadius(10); System.out.println("Reporting c1:"); System.out.println("x: + c1.getPositionx()); System. ut.println("y: " + c1.getPositionY()); System.out.println("r: " + c1.getRadius()); System.out.println("Area: " + 01.getArea()); Sample output Setting new position and radius for ci... Reporting c1: X: 20.0 y: 20.0 r: 10.0 Area: 314.1592653589793 8. isCollided With() checks whether this circle object is collided/overlapped with another circle object Parameter C-(Circle): define the circle object we want to check whether it collides with this circle. Return (boolean): return true if it is collided, false otherwise. . h g Not collided Not collided Collided Sample main() public static void main(String[] args) { System.out.println("Creating c1 and c2... "); // Creates Circle objects Circle c1 = new Circle(20, 20, 10); Circle c2 = new Circle(30, 10, 3); // Test the advanced function - isCollidedWith() if (c1.isCollidedWith(c2) == true) { System.out.println("c1 and c2 collide"); } else { System.out.println("c1 and c2 do not collide"); } Sample output Creating c1 and c2... c1 and c2 do not collide

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

What is a verb?

Answered: 1 week ago