Advertisement
d1i2p3a4k5

11.Area of triangle,circle,rectangle

Oct 18th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. abstract class shape
  4. {
  5.     int dim1,dim2;
  6.     void read()
  7.     {
  8.         Scanner t = new Scanner (System.in);
  9.         System.out.println("enter dim1 and dim2");
  10.         dim1 = t.nextInt();
  11.         dim2 = t.nextInt();
  12.         int z = dim1*dim2;
  13.         System.out.println("default area is "+z);
  14.     }
  15.     abstract void area();
  16. }
  17. class circle extends shape
  18. {
  19.     double area1;
  20.     void area()
  21.     {
  22.         Scanner t = new Scanner (System.in);
  23.         System.out.println("enter radius of circle");
  24.         int r = t.nextInt();
  25.         area1 = 3.142*r*r;
  26.    
  27.    
  28.         System.out.println("Area of circle is"+area1);
  29.     }
  30. }
  31. class rectangle extends shape
  32. {
  33.     int area2;
  34.     void area()
  35.     {
  36.         Scanner t = new Scanner(System.in);
  37.         System.out.println("enter lenght and breadth");
  38.         int l = t.nextInt();
  39.         int b = t.nextInt();
  40.         area2 = l*b;
  41.         System.out.println("Area of rectangle is"+area2);
  42.     }
  43. }
  44. class triangle extends shape
  45. {
  46.     int area3;
  47.     void area()
  48.     {
  49.         Scanner t = new Scanner(System.in);
  50.         System.out.println("enter height and base");
  51.         int h = t.nextInt();
  52.         int b = t.nextInt();
  53.         area3 = h*b/2;
  54.         System.out.println("Area of triangle is"+area3);
  55.     }
  56. }
  57. class test
  58. {
  59.     public static void main(String args[])
  60.     {
  61.         circle c = new circle ();
  62.         c.read();
  63.         c.area();
  64.         rectangle r = new rectangle();
  65.         r.area();
  66.         triangle t = new triangle();
  67.         t.area();
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement