1. Given the class Point below, define a class Circle that represents a circle with a given center and radius. The Circleclass should have an attribute named center as well as an integer radius The...

1 answer below ยป






1. 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 radius The center is a Point object, defined by the class Point. The class should also have these member ยซthe constructor of the class, which should take parameters to initialize all attributes ยซ a getter for each instance data, + asetter for each instance data ยซ an equals() method that returns true if two circles have same radii and false otherwise ยซ a circumference() method that returns the circumference of the circle + atoString() method that returns the summary of a Circle object puslic class Pointi private int x, vi public Point (int newX, int newยฅ{ x = new; y = newt; 3 public String teString(){ Tetum MaiteEen, Teyitey; 3 public double distance (Point other) { return Math.sqre (Math.pow (x-other.x,2) +Hath.pow(y-other.y,2)) 2. Write an application CircleTest that first creates two Points objects, point1 with random coordinates from 1 to 25, 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: 1. the summary of each circle 2. one of these two values: o the distance between their centers if the two circles are โ€œequalโ€ OR. ยฉ the average circumference, otherwise.
Answered 1 days AfterFeb 19, 2023

Answer To: 1. Given the class Point below, define a class Circle that represents a circle with a given center...

Ankur answered on Feb 19 2023
34 Votes
Last Name:
Name:
Professor:
Course:
Date:
1. Here, is the implementation of 1ST Que in JAVA.
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));
}
}
class Circle {
private Point center;
private int radius;
public Circle(Point newCenter, int newRadius) {
center = newCenter;
radius = newRadius;
}
public Point getCenter() {
return center;
}
public void setCenter(Point newCenter) {
center = newCenter;
}
public int getRadius() {
return radius;
}
public void setRadius(int newRadius) {
radius = newRadius;
}
public boolean equals(Circle other) {
return radius == other.radius;
}
public double circumference() {
return 2 * Math.PI * radius;
}
public String toString() {
return "Center: " + center + ", Radius: " + radius;
}
}
public class Main {
public static void main(String[] args) {
Point center = new Point(0, 0);
int radius = 5;
Circle circle = new Circle(center, radius);

System.out.println("Center: " + circle.getCenter());
System.out.println("Radius: " + circle.getRadius());

Point newCenter = new Point(1, 1);
circle.setCenter(newCenter);
circle.setRadius(10);

System.out.println("Center: " + circle.getCenter());
System.out.println("Radius: " + circle.getRadius());

Circle circle2 = new Circle(new Point(2, 2), 5);

if...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here