Write a program using following functions to calculate the area of following figures which returns the result to the called module.
1.double circle(double r)
2. float sphere(double r1)
3. double rectangle(double double b)
Answers
Explanation:
import java.util.Scanner;
public class KboatMenuArea
{
public void area() {
Scanner in = new Scanner(System.in);
System.out.println("Enter a to calculate area of circle");
System.out.println("Enter b to calculate area of square");
System.out.println("Enter c to calculate area of rectangle");
System.out.print("Enter your choice: ");
char choice = in.next().charAt(0);
switch(choice) {
case 'a':
System.out.print("Enter radius of circle: ");
double r = in.nextDouble();
double ca = (22 / 7.0) * r * r;
System.out.println("Area of circle = " + ca);
break;
case 'b':
System.out.print("Enter side of square: ");
double side = in.nextDouble();
double sa = side * side;
System.out.println("Area of square = " + sa);
break;
case 'c':
System.out.print("Enter length of rectangle: ");
double l = in.nextDouble();
System.out.print("Enter breadth of rectangle: ");
double b = in.nextDouble();
double ra = l * b;
System.out.println("Area of rectangle = " + ra);
break;
default:
System.out.println("Wrong choice!");
}
}
}