Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and...

Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { } //get method (Accessor Methods ) public double getRadius ( ) { return radius; } //set method (Mutator Methods) public void setRadius (double r) { radius=r; } public double findArea ( ) { return PI*radius*radius; //area= pi r squared } public double findCircumference ( ) { return 2 * PI * radius; } }//end Circle Now you can write a tester program called CircleDemo.java to create and use Circle objects. Compile and run it. Warning! If you cut and paste code from outside your IDE, it may result in errors – in particular, check that double quotes and hyphens are written correctly. public class CircleDemo{ public static void main(String[] args){ Circle cir1, cir2; cir1 = new Circle(); cir2 = new Circle(); cir1.setRadius(3.0); cir2.setRadius(11.01); System.out.println("Area of the first circle: " + cir1.findArea()); System.out.println("Circumference of the first circle: " + cir1.findCircumference()); System.out.println("Area of the second circle: " +cir2.findArea()); System.out.println("Circumference of the second circle: " +cir2.findCircumference()); } } 1 (b) Now make the following changes: ·In the Circle class, use the keyword this in the setRadius method ·In the Circle class, add a String attribute called colour that represents the colour of the circle ·In the Circle class, add the methods getColour and setColour. Use the keyword this in the new mutator method. ·In the Circle class, add another constructor that accepts both the radius and the colour and sets both attributes accordingly ·In the Circle class, add a toString method to print the radius, the area of the circle, and colour like this: Radius: 10 Area: -- Colour: Red ·Modify the CircleDemo program to read user given radius and colour from the keyboard, create the Circle object and print its radius, area and colour (using your toString method) and the circumference (using the findCircumference method): Enter the radius: 10 Radius: 10 Area: -- Colour: Red Circumference: ---
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here