Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.RoundingMode;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8.  
  9.  
  10. //Scanner Initialization
  11. Scanner input = new Scanner(System.in);
  12.  
  13.  
  14. //Variable Initialization
  15. double time1;
  16. double time2;
  17. double velocity1;
  18. double velocity2;
  19. double momentum1;
  20. double momentum2;
  21. double errorMomentum1;
  22. double errorMomentum2;
  23. double errorVelocity1;
  24. double errorVelocity2;
  25. double percentDifferent;
  26.  
  27. time1 = time2 = velocity1 = velocity2 = momentum1 = momentum2 = errorMomentum1 = errorMomentum2 = errorVelocity1 = errorVelocity2 = percentDifferent = 0;
  28.  
  29. double distance = .0249;
  30. double mass1 = 491.45;
  31. double mass2 = 496.51;
  32. double combinedMass = mass1 + mass2;
  33. double distanceError = .0002;
  34. double timeError = .00005;
  35. double massError = .1;
  36. double combinedMassError = .2;
  37.  
  38.  
  39. //Input
  40. System.out.println("Input time 1: ");
  41. time1 = input.nextDouble();
  42. System.out.println("Input time 2: ");
  43. time2 = input.nextDouble();
  44.  
  45.  
  46. //Math
  47. velocity1 = distance / time1;
  48. velocity2 = distance / time2;
  49. momentum1 = mass1 * velocity1;
  50. momentum2 = combinedMass * velocity2;
  51. double input1;
  52. double input2;
  53.  
  54. input1 = ((1/time1) * distanceError);
  55. input2 = ( (-(distance/(Math.pow(time1, 2)))) * timeError );
  56. errorVelocity1 = Math.sqrt( (Math.pow( input1, 2)) + (Math.pow( input2, 2)) );
  57.  
  58. input1 = ((1/time2) * distanceError);
  59. input2 = ( (-(distance/(Math.pow(time2, 2)))) * timeError );
  60. errorVelocity2 = Math.sqrt( (Math.pow( input1, 2)) + (Math.pow( input2, 2)) );
  61.  
  62. input1 = (velocity1 * massError);
  63. input2 = (mass1 * errorVelocity1);
  64. errorMomentum1 = Math.sqrt( (Math.pow(input1, 2)) + (Math.pow(input2, 2)) );
  65.  
  66. input1 = (velocity2 * combinedMassError);
  67. input2 = (combinedMass * errorVelocity2);
  68. errorMomentum2 = Math.sqrt( (Math.pow(input1, 2)) + (Math.pow(input2, 2)) );
  69.  
  70. input1 = Math.abs(momentum1 - momentum2);
  71. input2 = (.5 * (momentum1 + momentum2));
  72. percentDifferent = (input1/input2) * 100;
  73.  
  74.  
  75. //Rounding
  76. momentum1 = (Math.round(momentum1 * 100.0)) / 100.0;
  77. errorMomentum1 = (Math.round(errorMomentum1 * 100.0)) / 100.0;
  78.  
  79. momentum2 = (Math.round(momentum2 * 100.0)) / 100.0;
  80. errorMomentum2 = (Math.round(errorMomentum2 * 100.0)) / 100.0;
  81.  
  82. velocity1 = (Math.round(velocity1 * 10000.0)) / 10000.0;
  83. errorVelocity1 = (Math.round(errorVelocity1 * 10000.0)) / 10000.0;
  84.  
  85. velocity2 = (Math.round(velocity2 * 10000.0)) / 10000.0;
  86. errorVelocity2 = (Math.round(errorVelocity2 * 10000.0)) / 10000.0;
  87.  
  88.  
  89. //Formatting and Printing
  90. String finalMomentum1 = momentum1 + " ± " + errorMomentum1;
  91. String finalMomentum2 = momentum2 + " ± " + errorMomentum2;
  92. String finalVelocity1 = velocity1 + " ± " + errorVelocity1;
  93. String finalVelocity2 = velocity2 + " ± " + errorVelocity2;
  94.  
  95. System.out.println("Momentum 1: " + finalMomentum1);
  96. System.out.println("Momentum 2: " + finalMomentum2);
  97. System.out.println("Velocity 1: " + finalVelocity1);
  98. System.out.println("Velocity 2: " + finalVelocity2);
  99. System.out.println("Percent Difference: " + percentDifferent);
  100.  
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement