Question
Java Assignment: 1. A point in the x-y plane is represented by its x -coordinate and y -coordinate. For example, the origin has zero in
Java Assignment:
1. A point in the x-y plane is represented by its x-coordinate and y-coordinate. For example, the origin has zero in x-coordinate and zero in y-coordinate. Define a simple class Point to model a point in the x-y plane.
What properties a Point object should contain? When you define the class Point, use instance variable definitions for these properties.
Add one alternate constructor in the class Point, which takes arguments (parameters) to initialize instance variables.
Add queries to return x-coordinate and y-coordinate in the class Point.
Add commands to set x-coordinate and y-coordinate in the class Point.
Add toString() method in the class Point, which returns (x-coordinate, y-coordinate)", i.e., (0, 0).
2. Define a driver (test) class called TestPoint to test the class Point. You are asked to do the following things in the main of TestPoint:
Create a Point object for (5, 3);
Print the above Point object.
3. Using the class Point, define another class Circle to model a circle. A circle should have a center and a radius. You are asked to use composition. The Circle class contains:
A method that returns the center of circle, which should be a Point type
A method that returns circles area
A method that moves the circle (s center) to another position, the method heading is like:
public void move (Point newCenter) {}
A method that resize the circle radius according to the parameter. i.e., when the parameter is 0.5, the method halves the radius; when the parameter is 2.0, the method doubles the radius. The method heading is like:
public void resize (double resizeRate) {}
At least one alternate constructor which takes arguments (parameters) to initialize instance variables.
4. Define a driver (test) class called TestCircle to test the class Circle. You are asked to do the following things in the main of TestCircle:
a) Create a circle with origin as its center and radius of 1.0.
b) Print the circles center and area
c) Move the circle to position (-3, 6)
d) Shrink the circles radius to the half of original radius
e) Print the circles center and area
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