In: Computer Science
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object:
● Implicit constructor (default constructor)
● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle:
Area = pi * (r * r)
Your program includes a main class called Shape with a reference c1 to the Circle object. Pass the following values to the object Circle:
radius = 4
diameter = 8
pi = 3.14
Include output statements to view the values passed to the object Circle.
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object:
● Implicit constructor (default constructor)
● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle:
Area = pi * (r * r)
Your program includes a main class called Shape with a reference c1 to the Circle object. Pass the following values to the object Circle:
radius = 4
diameter = 8
pi = 3.14
Include output statements to view the values passed to the object Circle.
/* * Circle.java file */ class Circle { private int radius; private int diameter; private double pi; public Circle() { this.radius = 0; this.diameter = 0; this.pi = 3.14; } public Circle(int rad, int dia, double pi) { this.radius = rad; this.diameter = dia; this.pi = 3.14; } public void Calculate(double pi, int radius) { this.radius = radius; this.pi = pi; System.out.println("Area: " + this.pi*this.pi*this.radius); } } /* * Main.java file */ class Main { public static void main(String[] args) { int radius = 4; int diameter = 8; double pi = 3.14; Circle c1 = new Circle(4, 8, 3.14); c1.Calculate(pi, radius); } }
Note: For example drop queries.