Question
Complete the following coding in java

Create a class Circle that represents a round moving dot. A circle object needs to contain double variables to store the: Current X location of the circles center Current Y location of the circles center Radius of the circle Direction of the circles movement in radians Speed of the circles movement . . The Circle class must contain a constructor Circle double x, double y, double radius) that initializes the circles center x, y and radius. The Circle class must provide the following methods public double getY ) public void sety( double vert) public double getX () public void setx( double horz public double getSpeed ) public void setSpeed ( double fast ) /(#Set the speed of the circle*/ public double getDir ) public void setDir double compass Set the direction of the circle in radians/ public double getRadius) public void move( double time) Update the x coordinate to x +cos( direction)speedtime Update the y coordinate to y +sin( direction)speed time Returns the y coordinate of the center of circle. set the y coordinate Returns the x coordinate of the center of circle./ set the x coordinate/ Returns the speed ofthe circle Returnms the direction of movement Returms the radius of this circle./ Updates the x and y coordinates after the time / public boolean touches(Circle otherTrue if the other circle touches this circle/ True if the distance between the centers of the two circles, (-y2) is less than the sum of the two circles radii. Your Circle class must contain the following main method: public static void main (String[ unused) Box.animate () You will need to download the BounceFX.jar file and te jGRASP in Settings/ Classpath/ workspace/ Classpaths. Upload your completed Circle java file to Blackboard.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class Circle {
    double x, y, r;
    double dir, speed;

    public Circle(double x, double y, double radius) {
        this.x = x;
        this.y = y;
        this.r = radius;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getRadius() {
        return r;
    }

    public double getDir() {
        return dir;
    }

    public void setDir(double compass) {
        this.dir = compass;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public void move(double time) {
        x = x + Math.cos(dir) * speed * time;
        y = y + Math.sin(dir) * speed * time;
    }

    public boolean touches(Circle other) {
        double d = Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2));
        return (d < (other.r + r));
    }

}
Add a comment
Know the answer?
Add Answer to:
Complete the following coding in java Create a class Circle that represents a round moving dot....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • Question 11 (20 points) Given the class Point below, define a class Circle that represent a...

    Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...

  • U8ing separate files, write th definition for a clas called Poit and a class called Cirele...

    U8ing separate files, write th definition for a clas called Poit and a class called Cirele 1. The class point has the data members (double) and y (double) for the x and y coordinates The class has the following ember functions a) void set x (double) to set the x data member b) void set y(double) to set the y data member c) double get-x() to return th the data member d) double get yO to zeturn the the y...

  • Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An...

    Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An instance variable named x of type int. An instance variable named y of type int. Declare a method named toString() Returns a string representation of the point. Constructor that accepts values of all data members as arguments. Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point....

  • Write a java class definition for a circle object. The object should be capable of setting...

    Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { }    //get method (Accessor Methods ) public double getRadius (...

  • The following code computes the radius of a circle. Using static methods from the Math class...

    The following code computes the radius of a circle. Using static methods from the Math class complete the method that computes the radius of a circle using the formula  r2=(x-h)2 +(y-k)2 , given the (x,y) coordinates of one point on its circumference and the (h,k) coordinates of its center. public class Circle {    public static void main(String[] C)    {        double x1 =14.25;        double y1 =13.68;        double xCenter = 25.678;        double yCenter...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • Using the IST Linux system create the following Java command line inheritance application Lab4. Create the...

    Using the IST Linux system create the following Java command line inheritance application Lab4. Create the following project Java files: Point.java, Shape.java, Circle.java, Triangle.java, Rectangle.java, and Lab4.java Point.java will contain two coordinates x and y. This will be reused to create point objects to draw all the shapes. Shape.java will be the parent class and will contain a Point type. Circle.java, Triangle.java, Rectangle.java will all be children of Shapes.java class Each class (Circle, Triangle, Rectangle) will contain the private class...

  • Java Help 2. Task: Create a client for the Point class. Be very thorough with your...

    Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...

  • Exercise 2: There can be several constructors as long as they differ in number of parameters...

    Exercise 2: There can be several constructors as long as they differ in number of parameters or data type. Alter the program so that the user can enter just the radius, the radius and the center, or nothing at the time the object is defined. Whatever the user does NOT include (radius or center) must be initialized somewhere. There is no setRadius function and there will no longer be a setCenter function. You can continue to assume that the default...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT