This lab is to understand the concept of methods in JAVA Her
This lab is to understand the concept of methods in JAVA. Here we create two methods, CircleArea and RectangleArea to compute the area of a circle and a rectangle. The methods are then called in main program to show the areas of corresponding objects. 1) Complete the following program // (Name) // Lab 8 // CS1113 import java.util.Scanner; public class Lab9 { public static double CircleArea(double radius) { // Declare a variable areaOfCircle [Add code here] // Calculate the area of the circle using Math.PI method [Add code here] // return area of circle [Add code here] } // End of CircleArea method public static double RectangleArea(double length, double width) { // Declare a variable areaOfRect [Add code here] // Calculate the area of the rectangle [Add code here] // return area of rectangle [Add code here] } // End of RectangleArea method public static void main(String[] args) { // Declare any needed variables [Add code here] Scanner scan = new Scanner(System.in); // Prompt the user to enter the radius of the circle [Add code here] // Read the radius of circle as input from keyboard [Add code here] // Prompt the user to enter the length of the rectangle [Add code here] // Read the length of rectangle as input from keyboard [Add code here] // Prompt the user to enter the width of the rectangle [Add code here] // Read the width of rectangle as input from keyboard [Add code here] // Call the method that calculates area of circle with appropriate argument [Add code here] // Print the area of the circle [Add code here] // Call the method that calculates area of rectangle with appropriate arguments [Add code here] // Print the area of the rectangle [Add code here] } // End of main } // End of class Lab8 2) Add code for every comment to finish the program. Make sure you import any needed classes. 3) Run the program with the following input from keyboard: Radius of the circle: 5 Length of the rectangle: 10 Width of the rectangle: 15 4) The output should be as follows: Input the radius of the circle: 5 Input the length of the rectangle: 10 Input the width of the rectangle: 15 Circle Area = 78.54 Rectangle Area = 150.0 Solution
Ans1)
import java.util.Scanner;
{
public static double CircleArea(double radius)
{
// Declare a variable areaOfCircle
double areaOfCircle;
//[Add code here]
// Calculate the area of the circle using Math.PI method
areaOfCircle=Math.PI*radius*radius;
//[Add code here]
// return area of circle
return areaOfCircle;
//[Add code here]
} // End of CircleArea method
public static double RectangleArea(double length, double width)
{
// Declare a variable areaOfRect
double areaOfRect;
//[Add code here]
// Calculate the area of the rectangle
areaOfRect=length*width;
//[Add code here]
// return area of rectangle
return areaOfRect;
//[Add code here]
} // End of RectangleArea method
public static void main(String[] args)
{
// Declare any needed variables
double areaOfCircle;
double areaOfRect;
double radius;
double length,width;
//[Add code here]
Scanner scan = new Scanner(System.in);
// Prompt the user to enter the radius of the circle
System.out.println(\"Enter the radius of the circle :\");
//[Add code here]
// Read the radius of circle as input from keyboard
radius=scan.nextDouble();
//[Add code here]
// Prompt the user to enter the length of the rectangle
System.out.println(\"Enter the length of the rectangle :\");
//[Add code here]
// Read the length of rectangle as input from keyboard
length=scan.nextDouble();
//[Add code here]
// Prompt the user to enter the width of the rectangle
System.out.println(\"Enter the width of the ractangle :\");
//[Add code here]
// Read the width of rectangle as input from keyboard
width=scan.nextDouble();
//[Add code here]
// Call the method that calculates area of circle with appropriate argument
areaOfCircle = CircleArea(radius);
//for roundoff the calculated area upto 2 decimal
areaOfCircle = Math.round(areaOfCircle * 100.0) / 100.0;
//[Add code here]
// Print the area of the circle
System.out.println(\"Input the radius of the circle: \"+(radius));
System.out.println(\"Input the length of the rectangle: \"+length);
System.out.println(\"Input the width of the rectangle: \"+width);
System.out.println(\"Circle Area = \"+areaOfCircle);
//[Add code here]
// Call the method that calculates area of rectangle with appropriate arguments
areaOfRect=RectangleArea(length,width);
//for roundoff the calculated area upto 2 decimal
areaOfRect = Math.round(areaOfRect * 100.0) / 100.0;
// [Add code here]
// Print the area of the rectangle
System.out.println(\"Rectangle Area = \"+areaOfRect);
// [Add code here]
} // End of main
} // End of class Lab8
*******INPUT*****
Enter the radius of the circle : 5
Enter the length of the ractangle : 10
Enter the width of the rectangle : 15
*******INPUT*****
********OUTPUT*********
Input the radius of the circle: 5.0
Input the length of the rectangle: 10.0
Input the width of the rectangle: 15.0
Circle Area = 78.54
Rectangle Area = 150.0
********OUTPUT*********
Please let me know in case of any doubt,Thanks.


