Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- public class Area_exp{
- public static void main(String Args[])
- {
- Scanner sc = new Scanner(System.in);
- Area ar = new Area();
- int a,b,c;
- while(true)
- {
- System.out.print("\n\n1. Circle\n2. Rectangle\n3. Triangle\n4. Exit\n Enter your choice: ");
- int ch = sc.nextInt();
- switch(ch)
- {
- case 1:
- System.out.print("Enter a : ");
- a = sc.nextInt();
- System.out.println(ar.Area(a));
- break;
- case 2:
- System.out.print("Enter a : ");
- a = sc.nextInt();
- System.out.print("Enter b : ");
- b = sc.nextInt();
- System.out.println(ar.Area(a,b));
- break;
- case 3:
- System.out.print("Enter a : ");
- a = sc.nextInt();
- System.out.print("Enter b : ");
- b = sc.nextInt();
- System.out.print("Enter c : ");
- c = sc.nextInt();
- System.out.println(ar.Area(a,b,c));
- break;
- case 4:
- System.exit(0);
- }
- }
- }
- }
- class Area {
- int a;
- int b;
- int c;
- Area()
- {
- System.out.print("\tDefault Const called!\n");
- a = 0;
- b = 0;
- c = 0;
- }
- void Area()
- {
- System.out.print("\t exp\n");
- }
- Area(int a, int b, int c)
- {
- System.out.print("\tParameterized Const called!\n");
- this.a=a;
- this.b=b;
- this.c=c;
- }
- double Area(int a)
- {
- System.out.println("Area of Circle");
- double pi = 3.14;
- return a*a*pi;
- }
- double Area(int a, int b)
- {
- System.out.println("Area of Rectangle");
- return (double)(a*b);
- }
- double Area(int a, int b, int c)
- {
- System.out.println("Area of Triangle");
- double s = (a+b+c)/2;
- double area = Math.sqrt(s*(s-a)*(s-b)*(s-c));
- return area;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement