Pre-Condition: Reuse the code of Point class definition in the previous exercise that is defined as follows: - contains constructor with 2 arguments used to initialize x and y attributes - with setters and getter for x and y attributes Define a class called Circle to represent a circle. The Circle class has two data members, a Point object representing the center of the circle and a float value representing the radius. a. Include appropriate constructors for your Circle class. - constructor without argument for Test Case 1 and 2 - constructor with arguments for center and radius for Test Case 3 and 4

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 12SA: Assume the definition of class houseType as given in Exercise 11. Answer the following questions....
icon
Related questions
Question

Code the following in Java
Thank you

Pre-Condition: Reuse the code of Point class definition in the previous exercise that is defined
as follows:
- contains constructor with 2 arguments used to initialize x and y attributes
- with setters and getter for x and y attributes
Define a class called Circle to represent a circle. The Circle class has two data members, a
Point object representing the center of the circle and a float value representing the radius.
a. Include appropriate constructors for your Circle class.
- constructor without argument for Test Case 1 and 2
- constructor with arguments for center and radius for Test Case 3 and 4
b. Encapsulate the Circle attributes.
c. Also include methods for finding the area and circumference of the circle.
The return type of these methods should be float.
area = pi * radius * radius => Math.PI*radius*radius
circumference = 2 * pi * radius => 2*Math.PI*radius
HINTS:
1. Use the static constant pi in the Math class. For example,
Math.PI*radius*radius
2. Type cast the result of computation for area and circumference to float. For example:
float result = (float) Math.PI*radius* radius;
Note: Math.PI is double and therefore the result of the operation with it is double. Since the
methods to get area and circumference return float, result of the computation should be
typecasted to float.
d. Override the toString() method of the Object class. Return a String representation of your
Circle object according to the specified out out in the test cases. For example: The center of my
circle is at (2, 3) and the radius is 2.4
Transcribed Image Text:Pre-Condition: Reuse the code of Point class definition in the previous exercise that is defined as follows: - contains constructor with 2 arguments used to initialize x and y attributes - with setters and getter for x and y attributes Define a class called Circle to represent a circle. The Circle class has two data members, a Point object representing the center of the circle and a float value representing the radius. a. Include appropriate constructors for your Circle class. - constructor without argument for Test Case 1 and 2 - constructor with arguments for center and radius for Test Case 3 and 4 b. Encapsulate the Circle attributes. c. Also include methods for finding the area and circumference of the circle. The return type of these methods should be float. area = pi * radius * radius => Math.PI*radius*radius circumference = 2 * pi * radius => 2*Math.PI*radius HINTS: 1. Use the static constant pi in the Math class. For example, Math.PI*radius*radius 2. Type cast the result of computation for area and circumference to float. For example: float result = (float) Math.PI*radius* radius; Note: Math.PI is double and therefore the result of the operation with it is double. Since the methods to get area and circumference return float, result of the computation should be typecasted to float. d. Override the toString() method of the Object class. Return a String representation of your Circle object according to the specified out out in the test cases. For example: The center of my circle is at (2, 3) and the radius is 2.4
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr