icabit

shapes

Jul 1st, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. public class asd
  3. {
  4. static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
  5. public static void main(String args[])throws IOException
  6. {
  7.  
  8.  
  9. int x=0;
  10. int y=0;
  11. System.out.println("Choose a SHAPE");
  12. System.out.println("[1]Circle");
  13. System.out.println("[2]Triangle");
  14. System.out.println("[3]Square");
  15. x=Integer.parseInt(in.readLine());
  16. if ((x>=4)||(x
  17. {
  18. System.out.println("invalid option number");
  19. }
  20. else{
  21. if (x==1){
  22. System.out.println("Get C or A?");
  23. System.out.println("[1] C");
  24. System.out.println("[2] A");
  25. }
  26. if ((x==2)||(x==3)){
  27. System.out.println("Get A or P?");
  28. System.out.println("[1] A");
  29. System.out.println("[2] P");
  30. }
  31. System.out.println("enter the number of your choice:");
  32. y=Integer.parseInt(in.readLine());
  33. if ((y>=3)||(x
  34. {
  35. System.out.println("invalid option number");
  36. }
  37. else
  38. {
  39. cir(x,y);
  40. }
  41. }
  42. }
  43. public static void cir(int x,int y)throws IOException
  44. {
  45. double p=0;
  46. double b=0;
  47. double h=0;
  48. double q=0;
  49.  
  50. if ((x==1)&&(y==1))
  51. {
  52. System.out.println("Enter Radius:");
  53. p=Double.parseDouble(in.readLine());
  54. p=2*3.1416*p;
  55. System.out.println("Circumference is: "+p);
  56. }
  57. if ((x==1)&&(y==2))
  58. {
  59. System.out.println("Enter Radius:");
  60. p=Double.parseDouble(in.readLine());
  61. p=3.1416*(p*p);
  62. System.out.println("Area is: "+p);
  63. }
  64. if ((x==2)&&(y==1))
  65. {
  66. System.out.println("Enter Base:");
  67. b=Double.parseDouble(in.readLine());
  68. System.out.println("Enter Height:");
  69. h=Double.parseDouble(in.readLine());
  70. p=(b*h)/2;
  71. System.out.println("Area is: "+p);
  72. }
  73. if ((x==2)&&(y==2))
  74. {
  75. System.out.println("Enter 1st side:");
  76. b=Double.parseDouble(in.readLine());
  77. System.out.println("Enter 2nd side:");
  78. h=Double.parseDouble(in.readLine());
  79. System.out.println("Enter 3rd side:");
  80. p=Double.parseDouble(in.readLine());
  81. p=b+h+p;
  82. System.out.println("Perimeter is: "+p);
  83. }
  84. if ((x==3)&&(y==1))
  85. {
  86. System.out.println("Enter 1st side");
  87. b=Double.parseDouble(in.readLine());
  88. System.out.println("Enter 2nd side:");
  89. h=Double.parseDouble(in.readLine());
  90. p=b*h;
  91. System.out.println("Area is: "+p);
  92. }
  93. if ((x==3)&&(y==2))
  94. {
  95. System.out.println("Enter 1st side:");
  96. b=Double.parseDouble(in.readLine());
  97. System.out.println("Enter 2nd side:");
  98. h=Double.parseDouble(in.readLine());
  99. p=(2*b)+(2*h);
  100. System.out.println("Perimeter is: "+p);
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment