Guest User

Untitled

a guest
Jan 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.text.DecimalFormat;
  5.  
  6. /**
  7. *
  8. * @author Kayton
  9. */
  10. public class SimplePhysCalc {
  11.  
  12. /**
  13. * @param args the command line arguments
  14. */
  15. public static void main(String[] args) throws IOException {
  16. // TODO code application logic here
  17. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  18. double[] mag = new double[4];
  19. double[] angle = new double[4];
  20. double[] cos = new double[4];
  21. double[] sin = new double[4];
  22. double[] cos1 = new double[4];
  23. double[] sin1 = new double[4];
  24. DecimalFormat df = new DecimalFormat("0.000");
  25. System.out.println("Please enter vector magnitude 0: ");
  26. mag[0] = Double.parseDouble(br.readLine());
  27. System.out.println("Please enter angle 0: ");
  28. angle[0] = Double.parseDouble(br.readLine());
  29. System.out.println("");
  30. cos[0] = Math.cos(Math.toRadians(angle[0]));
  31. sin[0] = Math.sin(Math.toRadians(angle[0]));
  32. System.out.println("Please enter vector magnitude 1: ");
  33. mag[1] = Double.parseDouble(br.readLine());
  34. System.out.println("Please enter angle 1: ");
  35. angle[1] = Double.parseDouble(br.readLine());
  36. System.out.println("");
  37. cos[1] = Math.cos(Math.toRadians(angle[1]));
  38. sin[1] = Math.sin(Math.toRadians(angle[1]));
  39. System.out.println("Please enter vector magnitude 2: ");
  40. mag[2] = Double.parseDouble(br.readLine());
  41. System.out.println("Please enter angle 2: ");
  42. angle[2] = Double.parseDouble(br.readLine());
  43. System.out.println("");
  44. cos[2] = Math.cos(Math.toRadians(angle[2]));
  45. sin[2] = Math.sin(Math.toRadians(angle[2]));
  46. System.out.println("Please enter vector magnitude 3: ");
  47. mag[3] = Double.parseDouble(br.readLine());
  48. System.out.println("Please enter angle 3: ");
  49. angle[3] = Double.parseDouble(br.readLine());
  50. System.out.println("");
  51. cos[3] = Math.cos(Math.toRadians(angle[3]));
  52. sin[3] = Math.sin(Math.toRadians(angle[3]));
  53. System.out.println(mag[0] + "*cos(" + angle[0] + ") = " + mag[0] + "*(" + df.format(cos[0]) + ") = " + df.format(mag[0] * cos[0]));
  54. System.out.println(mag[0] + "*sin(" + angle[0] + ") = " + mag[0] + "*(" + df.format(sin[0]) + ") = " + df.format(mag[0] * sin[0]));
  55. System.out.println(mag[1] + "*cos(" + angle[1] + ") = " + mag[1] + "*(" + df.format(cos[1]) + ") = " + df.format(mag[1] * cos[1]));
  56. System.out.println(mag[1] + "*sin(" + angle[1] + ") = " + mag[1] + "*(" + df.format(sin[1]) + ") = " + df.format(mag[1] * sin[1]));
  57. System.out.println(mag[2] + "*cos(" + angle[2] + ") = " + mag[2] + "*(" + df.format(cos[2]) + ") = " + df.format(mag[2] * cos[2]));
  58. System.out.println(mag[2] + "*sin(" + angle[2] + ") = " + mag[2] + "*(" + df.format(sin[2]) + ") = " + df.format(mag[2] * sin[2]));
  59. System.out.println(mag[3] + "*cos(" + angle[3] + ") = " + mag[3] + "*(" + df.format(cos[3]) + ") = " + df.format(mag[3] * cos[3]));
  60. System.out.println(mag[3] + "*sin(" + angle[3] + ") = " + mag[3] + "*(" + df.format(sin[3]) + ") = " + df.format(mag[3] * sin[3]));
  61. System.out.println("");
  62. System.out.println("Because I don't have the graph, the signs may not be \n"
  63. + "correct on the calculations above. If you wish to invert\n"
  64. + "the sign of any of the numbers, do it manually in the next\n"
  65. + "set of calculations");
  66. System.out.println("");
  67. System.out.println("I will now combine all of the cosine values. I can \n"
  68. + "take in a maximum of 4 values. Please enter the desired values\n"
  69. + "above with their proper signs: (separate with enter, use 0's\n"
  70. + "if no value is desired)");
  71. cos1[0] = Double.parseDouble(br.readLine());
  72. cos1[1] = Double.parseDouble(br.readLine());
  73. cos1[2] = Double.parseDouble(br.readLine());
  74. cos1[3] = Double.parseDouble(br.readLine());
  75. double totCos = 0;
  76. for (double i : cos1) {
  77. totCos += i;
  78. }
  79. System.out.println("The total cosine value is " + df.format(totCos));
  80. System.out.println("");
  81. System.out.println("I will now combine all of the sine values. I can \n"
  82. + "take in a maximum of 4 values. Please enter the desired values\n"
  83. + "above with their proper signs: (separate with enter, use 0's\n"
  84. + "if no value is desired)");
  85. sin1[0] = Double.parseDouble(br.readLine());
  86. sin1[1] = Double.parseDouble(br.readLine());
  87. sin1[2] = Double.parseDouble(br.readLine());
  88. sin1[3] = Double.parseDouble(br.readLine());
  89. double totSin = 0;
  90. for (double i : sin1) {
  91. totSin += i;
  92. }
  93. System.out.println("The total sine value is " + df.format(totSin));
  94. System.out.println("");
  95. System.out.println("The total magnitude of the resultant vector is " + df.format(Math.sqrt((totSin*totSin) + (totCos*totCos))));
  96. double totTan = totSin/totCos;
  97. System.out.println("Tangent = Sine/cosine = (" + df.format(totSin) + ")/(" + df.format(totCos) + ") = " + df.format(totSin/totCos));
  98. System.out.println("The angle of the resultant vector is " + df.format(Math.toDegrees(Math.atan(totTan))) + " degrees.");
  99.  
  100. }
  101. }
Add Comment
Please, Sign In to add comment