Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.86 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.ArrayList;
  3.  
  4. /**
  5.  * Created by awes0me on 19-Oct-17.
  6.  */
  7. public class Main {
  8.     private static int repeatsNumber = 20;
  9.     private static Double[] baseValues;
  10.     private static Double[] secondValues;
  11.     private static Double[] measurementArray;
  12.     private static Double typeA;
  13.     private static Double typeB;
  14.     private static Double uT; // okresu
  15.     private static Double ut; // czasu
  16.     private static Double ul; // odległoci
  17.     private static Double ucg; // niepewność złożona przyspieszenia ziemksiego
  18.  
  19.     private static ArrayList<AccelerationCountingData> accelerationData;
  20.  
  21.     public static void main(String [ ] args) {
  22.         baseValues = createBaseValuesArray();
  23.         secondValues = createSecondValuesArray();
  24.         measurementArray = createMeasurementArray();
  25.         accelerationData = createAccelerationData();
  26.  
  27.         firstCounting();
  28.         printHelper("\n");
  29.         secondCounting();
  30.  
  31.         printHelper("\n");
  32.         printHelper("---------------");
  33.         printHelper("Average: ");
  34.         printHelper("---------------");
  35.         Double average = average(secondValues);
  36.         printHelper(String.valueOf(average));
  37.         printHelper("\n");
  38.  
  39.         typeA = countTypeA(baseValues, average);
  40.         printHelper("\n");
  41.         typeB = countTypeB(0.3);
  42.         printHelper("\n");
  43.  
  44.         ut = countUt();
  45.         ul = countUl();
  46.         uT = countUT();
  47.  
  48.         countAcceleration();
  49.     }
  50.  
  51.     // MARK - niepewność wyznaczenia okresu
  52.  
  53.     private static double countUT() {
  54.         double temp = sqrt(squared(typeA) + squared(ut));
  55.         return temp;
  56.     }
  57.  
  58.     private static double countUt() {
  59.         double temp = 0.01/sqrt(3.0);
  60.         return temp;
  61.     }
  62.  
  63.     private static double countUl() {
  64.         double temp = 0.1/sqrt(3.0);
  65.         return temp;
  66.     }
  67.  
  68. //    private static void countucg() {
  69. //        double pi = Math.PI;
  70. //        double piConstant = 4 * squared(pi);
  71. //        double x = sqrt((4*piConstant));
  72. //    }
  73.  
  74.     // MARK: - Type A counting - zad2
  75.  
  76.     private static double countTypeA(Double[] valueArray, Double average) {
  77.         double result;
  78.         double upperValue = 0;
  79.         double lowerValue = valueArray.length;
  80.  
  81.         for (Double item: valueArray) {
  82.             upperValue += squared(item - average);
  83.         }
  84.  
  85.         double temp;
  86.         temp = upperValue / lowerValue;
  87.         temp = sqrt(temp);
  88.         result = temp;
  89.         printHelper("---------------");
  90.         printHelper("Value of type A: ");
  91.         printHelper("---------------");
  92.         printHelper(String.valueOf(result));
  93.         return result;
  94.     }
  95.  
  96.     // MARK: - Type B counting - zad3
  97.  
  98.     private static double countTypeB(Double measureError) {
  99.         double result;
  100.         result = measureError / sqrt((double) 3);
  101.  
  102.         printHelper("---------------");
  103.         printHelper("Value of type B: ");
  104.         printHelper("---------------");
  105.         printHelper(String.valueOf(result));
  106.         return result;
  107.     }
  108.  
  109.     // MARK: - Earth acceleration - zad4
  110.  
  111.     private static void countAcceleration() {
  112.         double pi = Math.PI;
  113.         double piConstant = 4 * squared(pi);
  114.         printHelper("---------------");
  115.         printHelper("Value of Accelerations: ");
  116.         printHelper("---------------");
  117.  
  118.         for (AccelerationCountingData data: accelerationData) {
  119.             double result;
  120.             result = (piConstant * data.length) / data.time;
  121.             printHelper(String.valueOf(result));
  122.         }
  123.     }
  124.  
  125.     private static void firstCounting() {
  126.         printHelper("---------------");
  127.         printHelper("First Counting");
  128.         printHelper("---------------");
  129.         ArrayList<Double> results = new ArrayList<>();
  130.         results = countPeriods(baseValues);
  131.         for (Double item: results) {
  132.             printHelper(String.valueOf(item));
  133.         }
  134.     }
  135.  
  136.     private static void secondCounting() {
  137.         printHelper("---------------");
  138.         printHelper("Second Counting");
  139.         printHelper("---------------");
  140.         ArrayList<Double> results = new ArrayList<>();
  141.         results = countPeriods(secondValues);
  142.         for (Double item: results) {
  143.             printHelper(String.valueOf(item));
  144.         }
  145.         printHelper("\n");
  146.         printHelper("---------------");
  147.         printHelper("Squared:");
  148.         printHelper("---------------");
  149.         for (Double item: results) {
  150.             printHelper(String.valueOf(squared(item)));
  151.         }
  152.     }
  153.  
  154.     private static Double[] createMeasurementArray() {
  155.         Double[] tempArray;
  156.         tempArray = new Double[]{0.555, 0.515, 0.470, 0.600, 0.640};
  157.         return tempArray;
  158.     }
  159.  
  160.     private static Double[] createBaseValuesArray() {
  161.         Double[] tempArray;
  162.         tempArray = new Double[]{29.59, 29.34, 29.69, 29.75, 29.72, 29.53, 29.59, 29.75, 29.72, 29.62};
  163.  
  164.         return tempArray;
  165.     }
  166.  
  167.     private static Double[] createSecondValuesArray() {
  168.         Double[] tempArray;
  169.         tempArray = new Double[]{29.62, 29.75, 29.64, 28.60, 28.47, 28.60, 27.37, 27.41, 27.29, 30.93, 30.91, 30.72, 31.88, 31.88, 31.91};
  170.         return tempArray;
  171.     }
  172.  
  173.     private static ArrayList<AccelerationCountingData> createAccelerationData() {
  174.         ArrayList<AccelerationCountingData> tempArray = new ArrayList<>();
  175.         int counter = 0;
  176.         int measurementArrayCounter = 0;
  177.         for (Double time: secondValues) {
  178.             double length = 0.0;
  179.  
  180.             if (counter <= 2) {
  181.                 counter += 1;
  182.             } else {
  183.                 counter = 1;
  184.                 measurementArrayCounter += 1;
  185.             }
  186.             length = measurementArray[measurementArrayCounter];
  187.  
  188.             tempArray.add(new AccelerationCountingData(squared(countPeriod(time)), length));
  189.         }
  190.  
  191.         return tempArray;
  192.     }
  193.  
  194.     private static ArrayList<Double> countPeriods(Double [] array) {
  195.         ArrayList<Double> tempArray = new ArrayList<>();
  196.         for (Double item: array) {
  197.             Double result = item / repeatsNumber;
  198.             tempArray.add(result);
  199.         }
  200.         return tempArray;
  201.     }
  202.  
  203.     private static Double countPeriod(Double time) {
  204.         Double result = time / repeatsNumber;
  205.         return result;
  206.     }
  207.  
  208.     private static Double average(Double[] results) {
  209.         double result = 0;
  210.         for (Double item: results) {
  211.             result += item;
  212.         }
  213.         printHelper(String.valueOf(results.length));
  214.         return result / results.length;
  215.     }
  216.  
  217.     // MARK: - Helper
  218.  
  219.     private static void printHelper(String printed) {
  220.         System.out.println(printed);
  221.     }
  222.  
  223.     private static Double squared(Double x) {
  224.         return x * x;
  225.     }
  226.  
  227.     private static Double sqrt(Double x) {
  228.         return Math.sqrt(x);
  229.     }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement