Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.ArrayList;
- /**
- * Created by awes0me on 19-Oct-17.
- */
- public class Main {
- private static int repeatsNumber = 20;
- private static Double[] baseValues;
- private static Double[] secondValues;
- private static Double[] measurementArray;
- private static Double typeA;
- private static Double typeB;
- private static Double uT; // okresu
- private static Double ut; // czasu
- private static Double ul; // odległoci
- private static Double ucg; // niepewność złożona przyspieszenia ziemksiego
- private static ArrayList<AccelerationCountingData> accelerationData;
- public static void main(String [ ] args) {
- baseValues = createBaseValuesArray();
- secondValues = createSecondValuesArray();
- measurementArray = createMeasurementArray();
- accelerationData = createAccelerationData();
- firstCounting();
- printHelper("\n");
- secondCounting();
- printHelper("\n");
- printHelper("---------------");
- printHelper("Average: ");
- printHelper("---------------");
- Double average = average(secondValues);
- printHelper(String.valueOf(average));
- printHelper("\n");
- typeA = countTypeA(baseValues, average);
- printHelper("\n");
- typeB = countTypeB(0.3);
- printHelper("\n");
- ut = countUt();
- ul = countUl();
- uT = countUT();
- countAcceleration();
- }
- // MARK - niepewność wyznaczenia okresu
- private static double countUT() {
- double temp = sqrt(squared(typeA) + squared(ut));
- return temp;
- }
- private static double countUt() {
- double temp = 0.01/sqrt(3.0);
- return temp;
- }
- private static double countUl() {
- double temp = 0.1/sqrt(3.0);
- return temp;
- }
- // private static void countucg() {
- // double pi = Math.PI;
- // double piConstant = 4 * squared(pi);
- // double x = sqrt((4*piConstant));
- // }
- // MARK: - Type A counting - zad2
- private static double countTypeA(Double[] valueArray, Double average) {
- double result;
- double upperValue = 0;
- double lowerValue = valueArray.length;
- for (Double item: valueArray) {
- upperValue += squared(item - average);
- }
- double temp;
- temp = upperValue / lowerValue;
- temp = sqrt(temp);
- result = temp;
- printHelper("---------------");
- printHelper("Value of type A: ");
- printHelper("---------------");
- printHelper(String.valueOf(result));
- return result;
- }
- // MARK: - Type B counting - zad3
- private static double countTypeB(Double measureError) {
- double result;
- result = measureError / sqrt((double) 3);
- printHelper("---------------");
- printHelper("Value of type B: ");
- printHelper("---------------");
- printHelper(String.valueOf(result));
- return result;
- }
- // MARK: - Earth acceleration - zad4
- private static void countAcceleration() {
- double pi = Math.PI;
- double piConstant = 4 * squared(pi);
- printHelper("---------------");
- printHelper("Value of Accelerations: ");
- printHelper("---------------");
- for (AccelerationCountingData data: accelerationData) {
- double result;
- result = (piConstant * data.length) / data.time;
- printHelper(String.valueOf(result));
- }
- }
- private static void firstCounting() {
- printHelper("---------------");
- printHelper("First Counting");
- printHelper("---------------");
- ArrayList<Double> results = new ArrayList<>();
- results = countPeriods(baseValues);
- for (Double item: results) {
- printHelper(String.valueOf(item));
- }
- }
- private static void secondCounting() {
- printHelper("---------------");
- printHelper("Second Counting");
- printHelper("---------------");
- ArrayList<Double> results = new ArrayList<>();
- results = countPeriods(secondValues);
- for (Double item: results) {
- printHelper(String.valueOf(item));
- }
- printHelper("\n");
- printHelper("---------------");
- printHelper("Squared:");
- printHelper("---------------");
- for (Double item: results) {
- printHelper(String.valueOf(squared(item)));
- }
- }
- private static Double[] createMeasurementArray() {
- Double[] tempArray;
- tempArray = new Double[]{0.555, 0.515, 0.470, 0.600, 0.640};
- return tempArray;
- }
- private static Double[] createBaseValuesArray() {
- Double[] tempArray;
- tempArray = new Double[]{29.59, 29.34, 29.69, 29.75, 29.72, 29.53, 29.59, 29.75, 29.72, 29.62};
- return tempArray;
- }
- private static Double[] createSecondValuesArray() {
- Double[] tempArray;
- 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};
- return tempArray;
- }
- private static ArrayList<AccelerationCountingData> createAccelerationData() {
- ArrayList<AccelerationCountingData> tempArray = new ArrayList<>();
- int counter = 0;
- int measurementArrayCounter = 0;
- for (Double time: secondValues) {
- double length = 0.0;
- if (counter <= 2) {
- counter += 1;
- } else {
- counter = 1;
- measurementArrayCounter += 1;
- }
- length = measurementArray[measurementArrayCounter];
- tempArray.add(new AccelerationCountingData(squared(countPeriod(time)), length));
- }
- return tempArray;
- }
- private static ArrayList<Double> countPeriods(Double [] array) {
- ArrayList<Double> tempArray = new ArrayList<>();
- for (Double item: array) {
- Double result = item / repeatsNumber;
- tempArray.add(result);
- }
- return tempArray;
- }
- private static Double countPeriod(Double time) {
- Double result = time / repeatsNumber;
- return result;
- }
- private static Double average(Double[] results) {
- double result = 0;
- for (Double item: results) {
- result += item;
- }
- printHelper(String.valueOf(results.length));
- return result / results.length;
- }
- // MARK: - Helper
- private static void printHelper(String printed) {
- System.out.println(printed);
- }
- private static Double squared(Double x) {
- return x * x;
- }
- private static Double sqrt(Double x) {
- return Math.sqrt(x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement