Exercises assigned on object modeling with JaVA

Shared solutions on the classroom site of the course…

Shared solutions on the classroom site of the course… Exercise A Model the Circle object, whose objects represent circles in the plane. The class has the following constructor and instance methods: 1) public Circle(double r): constructor to create a Circle object that represents a circle with radius r (remember that the double type indicates real numbers). 2) public double diameter(): method that returns the diameter of the circle represented by the receiving object. 3) public double perimeter(): method that returns the perimeter of the circle represented by the receiving object. 4) public double area(): method that returns the area of the circle represented by the receiving object. 5) public Circle sumRadius(Circle c): method that returns a new Circle object whose radius is the sum of the radii of the circles represented by the receiving object and object c. Write a class named UseCircle, having only the special main method. This method must perform these actions: 1. Have the user enter the radii r1 and r2 of two circles in the plane through the keyboard. 2. Create two Circle objects, c1 and c2, with radii r1 and r2 respectively. 3. Print the diameter, perimeter, and area of the circles represented by c1 and c2 on the standard output. 4. Create a third Circle object c3, which represents a circle with a radius equal to the sum of the radii of the circles represented by c1 and c2. 5. Print the diameter, perimeter, and area of the circle represented by c3 on the standard output. At the end of writing the class, compile it and run it several times, trying to vary the input data requested by the program. Exercise B Model an object called StringManipulator that represents a string and has some methods to manipulate it. The constructor and instance methods of the class are the following: 1. public StringManipulator(String s): constructor to create a StringManipulator object that represents the string s. 2. public String reverse(): method that returns a new string obtained by reversing the string represented by the receiving object (i.e., reading its characters from right to left). 3. public String removeSpaces(): method that returns a new string obtained by removing white spaces from the string represented by the receiving object. 4. public String concatenateWith(String s): method that returns a new string obtained by concatenating (i.e., juxtaposing) the string represented by the receiving object with the string s. Write a class named UseStringManipulator, having only the special main method. This method must perform these actions: 1. Have the user enter any string str. 2. Create a StringManipulator object ms that represents the string str. 3. Using the methods of ms, display to the user in a graphical window the string str read from right to left and then the string str cleaned of white spaces and repeated twice. The repetition of the string must be done through the concatenateWith(..) method. For example, if the user entered the string hello world, the program should display the following messages: reversed string: dlrow olleh string without spaces and repeated twice: helloworldhelloworld