Advertisement
Fakhru

Untitled

Jun 29th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package input;
  6.  
  7. /**
  8. *
  9. * @author MPA3
  10. */
  11.  
  12. // Coded By Fakhrurazi <3
  13.  
  14.  
  15. import java.util.Scanner;
  16. public class Input {
  17.  
  18. /**
  19. * @param args the command line arguments
  20. */
  21. public static void main(String[] args) {
  22. final double pi = 3.142;
  23. int graphHeight, graphWidth, angle, aspectedGraphHeight, row, column, x, y, angleStep;
  24. int radius;
  25. int ans;
  26.  
  27.  
  28. //String s = "";
  29. System.out.println("|Area of Circle Calculator|");
  30. System.out.println("Choose Mode: \n1.Diameter\n2.Radius");
  31. Scanner input = new Scanner(System.in);
  32. int sel = input.nextInt();
  33. if(sel == 1){
  34.  
  35. System.out.println("Insert value in Diameter: ");
  36. ans = input.nextInt();
  37. // ans = (diameter/2) * (daimeter/2);
  38. System.out.println("The area of circle is: " + (pi * (ans/2) * (ans/2) ));
  39.  
  40. }else if(sel == 2){
  41.  
  42. System.out.println("Insert value in Radius: ");
  43. ans = input.nextInt();
  44. //radius = radius2;
  45. System.out.println("The area of circle is: " + (pi * ans * ans));
  46.  
  47.  
  48. }else {
  49.  
  50. System.out.println("Wrong Selection. Exiting...");
  51. }
  52. char[][] circle = new char [150][150];
  53. // Scanner in = new Scanner(System.in);
  54.  
  55.  
  56. System.out.print("\n\n\t\t\t###### Draw circle #######\n");
  57. //System.out.print( "\n\t\tEnter graph Height: ");
  58. //graphHeight = in.nextInt();
  59. graphHeight = 20;
  60. //System.out.print( "\t\tEnter graph Width: ");
  61. //graphWidth = in.nextInt();
  62. graphWidth = 20;
  63. System.out.print( "\t\tRadius of circle: ");
  64. radius = input.nextInt();
  65. //radius = ans;
  66.  
  67.  
  68. //converting degree to radian by multiplying with pi/180
  69. angle = (int)(360 * Math.PI/180);
  70.  
  71. //.5 is for precision
  72. aspectedGraphHeight = (int)(graphHeight/2.0);
  73.  
  74.  
  75. // define graphpaper
  76. for(row=0; row<=aspectedGraphHeight; row++)
  77. {
  78. for(column=0; column<=graphWidth; column++)
  79. {
  80. circle[row][column]=' ';
  81. }
  82. }
  83.  
  84. //horizontal axis
  85. for(column = 0; column <= graphWidth; column++)
  86. {
  87. row = aspectedGraphHeight / 2;
  88. circle[row][column] = '-';
  89. }
  90.  
  91. //vertical axis
  92. for(row = 0; row <= aspectedGraphHeight; row++)
  93. {
  94. column = graphWidth / 2;
  95. circle[row][column] = '|';
  96. }
  97.  
  98. //points of circle
  99.  
  100. for (angle = 0; angle <= 360; angle += 1)
  101. {
  102. x = (int)(radius * Math.cos(angle));
  103. y = (int)(radius * Math.sin(angle));
  104.  
  105. row = (aspectedGraphHeight/2 - y/2);
  106. // y is divided by scaling factor 2 for aspected ratio of characters in terminal
  107. column = graphWidth/2 + x;
  108. circle[row][column] = '.';
  109. }
  110.  
  111.  
  112. //print circle
  113. for(row = 0; row<=aspectedGraphHeight; row++)
  114. {
  115. for(column = 0; column<=graphWidth; column++)
  116. System.out.print(circle[row][column]);
  117. System.out.println(" ");
  118. }
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement