Click here to Skip to main content
15,890,946 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Develop an Interface Colourfulto the following specifications:
1. It has a public method fillMyColour(). The method has one
String argument which is colourNameand it does not return any
value.


Write a Java program to develop a class Circle with the following specifications:
1. The class has one private attribute: radius, of type double.
2. The class has one-argument constructor that sets the value of its instance variable to
given value.
3. The class has a zero-argument constructor that sets the value of its instance variable to
its default values. It should invoke the one-argument constructor.
4. The class has public accessor and mutator methods for its attribute.
5. The class has a public method getArea() that takes no argument and returns area of
circle. Note that the area of the circle = radius2 * PI. Where PI= 3.14.
6. The class has a public method getPerimeter() that takes no argument and returns
the perimeter of the circle. Hint: Perimeter of the circle = 2*PI*r
7. Override the Object’s toString() method in order to return a string representation
of the Circle status as:
Radius = , area = , perimeter =




Write a Java program to develop a class Circle2D with the following specifications:
1. Class Circle2D inherits Circle class and implements Colourful interface.
2. The class has three private attributes: color of type String, x, and y (both of type
double), x and y attributes specify the center of the circle.
3. The class has a Three-argument constructor that sets the value of its x, y, and radius to
given values. It should invoke its super-class constructor.
4. The class has a zero-argument constructor that sets the value of its instance variables to
their default values. It should invoke its Three–argument constructor in the same class.
5. The class has to implement fillMyColour() method, which assign the given string
value to the color instance variable.
6. The class has a private method distance (double x1, double y1,
double x2, double y2) that returns the distance between (x1,y1) and (x2, y2).
Hint: distance between two points= (𝑥2 − 𝑥1)
2 + (𝑦2 − 𝑦1)
2
7. The class has a public method contains(double x1, double y1) that returns
true if ( x1, y1) is inside the circle.
Hint: (x1, y1) is contained in the circle if the distance between (x1, y1) and the center
of the circle represented by attributes (x,y) less than or equal radius of the circle.
8. The class has a public method contains(Circle2D circle1) that returns true
if the specified circle1 is inside this circle. Hint: the current circle contains
circle1 if the distance between the two centers of the circles + circle1.radius
less than or equal to this.radius.
9. The class has a public method overlaps(Circle2D circle1) that returns true
if the specified circle1 overlaps with this circle. Hint: Two circles overlap if the
distance between the two centers are less than or equal to this.radius +
circle1.radius.
10.Override the Object’s toString() method in order to return a string representation
of the Circle2D instance variables as the below format, it should invoke its superclass
toString() method:
radius = , area = , perimeter = , center point of the circle: , color is





Develop a public class MyCircles to the following specifications:
1. The class has a private instance ArrayList<Circle2D>, which represent a collection
of Circle2D.
2. The class has a zero-argument constructor that creates and initializes the
ArrayList<Circle2D> instance object.
3. The class has a public method void addCircle2D (Object, String) which is
used to add an instance object of Circle2D into the ArrayList. The String
represents the name of the color that will fill the circle2D object.
4. The class has the method readFromFile (String). It reads from a text file which its
name given as a string argument of the method. Then fills the ArrayList collection with
the values of the circle2D instance objects. Hint: Each line in the file has 4 values
representing x, y, and radius of type double consequently, followed by a string value
represent the color.
5. The class has the method printAll(). It displays either a string representing each
element in the ArrayList (one per line) or a string message that “NO Shapes are available”.
6. The class has the method check_Overlaps_Contains(), which displays which
circles of the ArrayList are overlapped with each other, or contained in each other. The
method should print a message format as follows:
Checking Overlaps and Contains
******************************
Circle: 0 with red color:
Overlaps with Circle:1 that has yellow color.
……………..
Contains Circle:2 that has blue color.
……………..
Circle: 1 with yellow color:
Overlaps with Circle:0 that has red color.
Contains Circle:0 that has red color.
Overlaps with Circle:2 that has blue color.
……………………..
Hint: 0 and 1 represent the index of the objects in the ArrayList.
7. The class has the method check_contains_point(double x, double y),
which displays which circles of the ArrayList contains point(x,y). The method should
print a message format as follows:
The following circles containing the Point (…, ….)
**********************************************
Circle: 0 with red color.
…………………………………………….







Develop a public class TestCircles to the following specifications:
1. You are required to declare and create as an instance object of class MyCircles.
2. You are required to read from the file “c:\circles.txt” (Attached) and fill the
collection of the instance object of class MyCircles.
3. You are required to print the values of myCircles object on the screen.
4. Displays which circles of MyCircles object are overlapping with each other, and which
are contained in each other.
5. Displays which circles of MyCircles object contain the point(3,3).

What I have tried:

i tired all Classes before the Mycircles class
Posted
Updated 2-May-18 10:35am
v2
Comments
Mehdi Gholam 2-May-18 13:19pm    
Looks like homework.
Richard MacCutchan 2-May-18 14:20pm    
We already told you in your previous question, that no one is going to write your code for you.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

If you have tried something, and it doesn't work, then show us the relevant code fragments, and explain how they don't work: what you did to test them, what you expected to happen, what did happen, and what you did to find out why they differed.

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Quote:
I hate array list btw :D

For peace of your mind, you may think about another job. A professional programmer deal with array/list in a daily fashion.

So, you show no attempt to solve the problem yourself, you have no question, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900