Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- //Scanner Initialization
- Scanner input = new Scanner(System.in);
- //Variable Initialization
- double time1;
- double time2;
- double velocity1;
- double velocity2;
- double momentum1;
- double momentum2;
- double errorMomentum1;
- double errorMomentum2;
- double errorVelocity1;
- double errorVelocity2;
- double percentDifferent;
- time1 = time2 = velocity1 = velocity2 = momentum1 = momentum2 = errorMomentum1 = errorMomentum2 = errorVelocity1 = errorVelocity2 = percentDifferent = 0;
- double distance = .0249;
- double mass1 = 491.45;
- double mass2 = 496.51;
- double combinedMass = mass1 + mass2;
- double distanceError = .0002;
- double timeError = .00005;
- double massError = .1;
- double combinedMassError = .2;
- //Input
- System.out.println("Input time 1: ");
- time1 = input.nextDouble();
- System.out.println("Input time 2: ");
- time2 = input.nextDouble();
- //Math
- velocity1 = distance / time1;
- velocity2 = distance / time2;
- momentum1 = mass1 * velocity1;
- momentum2 = combinedMass * velocity2;
- double input1;
- double input2;
- input1 = ((1/time1) * distanceError);
- input2 = ( (-(distance/(Math.pow(time1, 2)))) * timeError );
- errorVelocity1 = Math.sqrt( (Math.pow( input1, 2)) + (Math.pow( input2, 2)) );
- input1 = ((1/time2) * distanceError);
- input2 = ( (-(distance/(Math.pow(time2, 2)))) * timeError );
- errorVelocity2 = Math.sqrt( (Math.pow( input1, 2)) + (Math.pow( input2, 2)) );
- input1 = (velocity1 * massError);
- input2 = (mass1 * errorVelocity1);
- errorMomentum1 = Math.sqrt( (Math.pow(input1, 2)) + (Math.pow(input2, 2)) );
- input1 = (velocity2 * combinedMassError);
- input2 = (combinedMass * errorVelocity2);
- errorMomentum2 = Math.sqrt( (Math.pow(input1, 2)) + (Math.pow(input2, 2)) );
- input1 = Math.abs(momentum1 - momentum2);
- input2 = (.5 * (momentum1 + momentum2));
- percentDifferent = (input1/input2) * 100;
- //Rounding
- momentum1 = (Math.round(momentum1 * 100.0)) / 100.0;
- errorMomentum1 = (Math.round(errorMomentum1 * 100.0)) / 100.0;
- momentum2 = (Math.round(momentum2 * 100.0)) / 100.0;
- errorMomentum2 = (Math.round(errorMomentum2 * 100.0)) / 100.0;
- velocity1 = (Math.round(velocity1 * 10000.0)) / 10000.0;
- errorVelocity1 = (Math.round(errorVelocity1 * 10000.0)) / 10000.0;
- velocity2 = (Math.round(velocity2 * 10000.0)) / 10000.0;
- errorVelocity2 = (Math.round(errorVelocity2 * 10000.0)) / 10000.0;
- //Formatting and Printing
- String finalMomentum1 = momentum1 + " ± " + errorMomentum1;
- String finalMomentum2 = momentum2 + " ± " + errorMomentum2;
- String finalVelocity1 = velocity1 + " ± " + errorVelocity1;
- String finalVelocity2 = velocity2 + " ± " + errorVelocity2;
- System.out.println("Momentum 1: " + finalMomentum1);
- System.out.println("Momentum 2: " + finalMomentum2);
- System.out.println("Velocity 1: " + finalVelocity1);
- System.out.println("Velocity 2: " + finalVelocity2);
- System.out.println("Percent Difference: " + percentDifferent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement