Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Homework 4 1. Given the class Point below, define a class Circle that represent a circle with a given center and radius. The Circle class
Homework 4 1. 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 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 each instance data a setter for each instance data a toString() method that returns the summary of a Circle object 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)); } } 2. Write an application CircleTest that first creates two Points objects, point1 with random coordinates from 1 to 10, inclusive, and point2 with coordinates 0,0. The program will then instantiate two circles with the following radius/center requirements: 1. Radius entered from the keyboard and point2 as the center 2. Radius 5.5 and point1 as the center The program prints to the screen the summary of each circle as well as the distance between their centers (for full credit, you MUST use the circle objects)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started