Question
1- Create a class called Point that has two instance variables, defined as private, as follows: An x coordinate and a y coordinate of type
1- Create a class called Point that has two instance variables, defined as private, as follows: An x coordinate and a y coordinate of type integer. a) Write two constructors for the Point class as follows: A default constructor that sets the class instance variables to zero and a constructor that receives two integer values and sets the instance variables to them. b) Write the set and get methods for the Point class to set and return the values of its instance variables. c) Write a toString() method for the Point class that prints the class name (Point) and the value of its instance variables. 2- Create three classes called Circle, Rectangle and Square with the following properties:
- The Circle class has two instance variables a position of type Point (the class that you just created above) and a radius of type double. The instance variables position and radius specify the position of the center and radius of the circle, respectively. - The Rectangle class has three instance variables a position of type Point (the class that you just created above), a length and a width of type double. The instance variables position, length and width specify the position of the top left corner, length and width of the rectangle, respectively. - The Square class has two instance variables a position of type Point (the class that you just created above) and a length of type double. The instance variables position and length specify the position of the top left corner and length of the square, respectively. For each of the Circle, Rectangle andSquare classes do the following: a) Define the instance variables as private. b) Write two constructors for each class as follows: A default constructor that sets the instance variables to zero and a constructor that receives values for the instance variables and sets them. c) Write the set and get methods for each class to set and return the values of their instance variables. For example, one of the get methods would return a Point. d) Write a toString() method for each class that prints the class name (Circle, Rectangle or Square) and the value of its instance variables. e) Write two methods called getPerimeter() and getArea() for each class, which calculate and return the perimeter and area of the class, respectively. For example, the getArea() method of the Square class returns the area of the Square object. 3- Test the above classes by writing a class called GeometricTest.java that does the following: - Creates instances of the Circle, Rectangle and Square classes as follows: - Circle: positioned at x = 7, y = 3 and the radius = 4.5. - Rectangle: positioned at x = 3, y = -1 and the length = 4.0 and width = 6.0. - Square: positioned at x = 5, y = 8 and the length = 2.0. - Prints each of the above objects. - Changes the length of the Square object to 5.0. - Prints the perimeter and area of each of each of the above objects. - Compares the x coordinates of the Square and Rectangle classes and prints a message specifying which one of them has a larger x coordinate.
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