Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write simple java code & explain. WRITING CLASSES Given the class Point below, define a class Circle that represents a circle with a given

Please write simple java code & explain. WRITING CLASSES
Given the class Point below, define a class Circle that represents a circle with a given center and radius. The Circle class should have an attribute named center as well as an integer attribute named radius. 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
getters for each instance data
setters for each instance data
an equals() method that compares two circle objects for equality. The method returns true if two circles have same radii and false otherwise
a circumference() method that returns the circumference of the circle
a toString() method that returns the summary of a Circle object, e.g.
"Circle with radius 5, center x:0,y:0"
public class Point{
private int x, y;
public Point(int newX, int newY{
x = newX;
y = newY;
}
public String toString(){
return "x:"+x+","+"y:"+y;
}
public double distance(Point other){
return Math.sqrt(Math.pow(x-other.x,2)+Math.pow(y-other.y,2));
}
}
Write an application CircleTest that first creates two Points objects, F point1 with random coordinates from 1 to 20, inclusive, and point2 with coordinates 0,0. The program will then instantiate two circles with the following radius/center requirements:
Radius entered from the keyboard and point1 as the center
Radius 5 and point2 as the center
The program prints to the screen:
the summary of each circle
one of these two values:
the distance between their centers if the two circles are equal OR
the average circumference, otherwise.
For full credit, you MUST use the circle objects and their instance methods when producing the two values to display.

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

What are the need and importance of training ?

Answered: 1 week ago

Question

What is job rotation ?

Answered: 1 week ago