Hello folks i have been working on a code for a couple hours now and decided i need help. I am a beginner in java but usually learn quick. Ill first post the info on the code then post the two versions i have. Any help is greatly appreciated.
Code Info:
A 10-element double array, called ref, holds the weekly reference temperatures used in a
physical process. The process is run five days a week and the 10 temperatures actually
observed in the process on a single day are recorded in an array called obs (number of elements in
obs is 10). The elements in the two arrays have a one-to-one correspondence; e.g., ref[3] and obs[3] refer to
the reference and observed temperatures of the same physical entity.
For a given day of the week, the total deviation (for all the 10 entities) of the observed values from the reference
values is measured as the RMS (root mean squared) deviation:
daily total deviation = sqrt((1/10) * sum_{i= 1 to 10 elements} (ref[i] - obs[i])^{2}))
What it should do:
The program should simulate the RMS deviations for each of the five days of the week.
For a given week, the reference temperatures are fixed (all five days of a given week have the same
reference temperatures), but for two different weeks they are different. The actual temperatures are observed and recorded daily.Print the reference temperatures and the total RMS deviation for each of the five days of a given week.
The input to the program is:
an integer between 1 and 52 to indicate the week of the year.
The outputs are:
(i) the 10 reference values for the week and (ii) 5 RMS deviations, one for each day of the given week.
Use the java random number generator Random and the method nextDouble() (as discussed in class) to obtain
the temperature values. Use initial seed value(s) (don't use system-supplied seeds) so that different
runs of your program with the same input produce the same results (i.e., your program should produce exactly the same output when supplied with the same initial seed(s) and the same input). Note that ref[] and obs[] are one-dimensional arrays: do not make obs two-dimensional in an attempt to hold all 5 days. Use a loop for the five days of the week.
HELP:
My 1st code: Temperature.java
public class Temperature { public static void main(String[] args) { char[] ref = createArray(); System.out.println("Enter a integer between 1 and 52 to indicate the week o f the year: "); displayArray(ref); int[] counts = countLetters(chars); System.out.println(); System.out.println("The 10 reference values for the week are: "); displayCounts(counts); public static char[] createArray() { char[] ref = new char[52]; for (int i = 0; i < chars.length; i++) chars[i] = Random
My 2nd code: weektemp.java
public class weektemp { public static void main(String[] args) { // declares an array of integers int[] anArray; // allocates memory for 10 integers anArray = new int[10]; // initialize first element anArray[0] = 100; // initialize second element anArray[1] = 200; // etc. anArray[2] = 300; anArray[3] = 400; anArray[4] = 500; anArray[5] = 600; anArray[6] = 700; anArray[7] = 800; anArray[8] = 900; anArray[9] = 1000; System.out.println("Reference value 0: " + anArray[0]); System.out.println("Reference value 1: " + anArray[1]); System.out.println("Reference value 2: " + anArray[2]); System.out.println("Reference value 3: " + anArray[3]); System.out.println("Reference value 4: " + anArray[4]); System.out.println("Reference value 5: " + anArray[5]); System.out.println("Reference value 6: " + anArray[6]); System.out.println("Reference value 7: " + anArray[7]); System.out.println("Reference value 8: " + anArray[8]); System.out.println("Reference value 9: " + anArray[9]); } } public static double rms(double[] nums){ double ms = 0; for (int i = 0; i < nums.length; i++) ms += nums[i] * nums[i]; ms /= nums.length; return Math.sqrt(ms); } public static void main(String[] args){ double[] nums = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}; System.out.println("The 5 RMS deviations are: + rms(nums)"); } }