import java.io.BufferedReader; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.IOException; import java.io.InputStreamReader; /** * * @author STUDENT */ class square{ String Shape; int side; public void compute1(String a){ int area= side*side; System.out.println("Area of "+Shape+ " is: "+area); } } class rectangle{ String Shape; int length; int width; public void compute2(String a){ int area= width*length; System.out.println("Area of "+Shape+ " is: "+area); } } class triangle{ String Shape; int base; int height; public void compute3(String a){ int area= base*height/2; System.out.println("Area of "+Shape+ " is: "+area); } } public class Figure { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is the shape of your figure?"); System.out.println("[S] Square"); System.out.println("[R] Rectangle"); System.out.println("[T] Triangle"); System.out.println("What is your choice? "); String strChoice=br.readLine(); char choice= strChoice.charAt(0); switch (choice){ case 'S': case 's': square s= new square(); s.Shape= "Square"; System.out.println("side: "); String strSide= br.readLine(); s.side= Integer.parseInt(strSide); s.compute1(s.Shape); break; case 'R': case 'r': rectangle r= new rectangle(); r.Shape= "Rectangle"; System.out.println("length: "); String strLength= br.readLine(); r.length= Integer.parseInt(strLength); System.out.println("width: "); String strWidth= br.readLine(); r.width= Integer.parseInt(strWidth); r.compute2(r.Shape); break; case 'T': case 't': triangle t= new triangle(); t.Shape= "Triangle"; System.out.println("base: "); String strBase= br.readLine(); t.base= Integer.parseInt(strBase); System.out.println("height: "); String strHeight= br.readLine(); t.height= Integer.parseInt(strHeight); t.compute3(t.Shape); break; } } }