public static int[] convertArgs(String[] args)That is, given an array of Strings your method will convert each of the strings into an integer, and return an array of integers. For instance, suppose your program was named Utilities (and it is in the file Utilities.java) then given the command line java Utilities 1 1 2 3 5 8 13 your convertArgs function would receive an array
["1", "1", "2", "3", "5", "8", "13"]and would return the array
[1,1,2,3,5,8,13]If the command line arguments contain a non-integer it is OK for your program to die.
int[] arr = new int[2]; arr[0]=1; arr[1]=21; System.out.println(arr);You do not get the contents of the array, rather you get something incomprehensible like [DA34B55398. This is the value of the pointer to the array, which had nothing to do with its contents. So write a method that takes an array and prints out its contents in a nice table. For instance, given arr as above, the table might look like:
0 1 2 21Do not worry about getting things into nicely aligned columns.
The signature of this method should be
public static void printArray(int[] nums)
public static double computeAverage(int[] nums)For example, given an array[1,1,2,3,5,8,13], this function should return 4.714285714285714 (the number of decimals you print may be different).
sqrt( (sum( (x[i])-average(x))*(sum(x[i])-average(x))) / x.length-1 )For instance, given the array [1,1,2,3,5,8,13] the calculation of standard deviation would look like
aver = 4.7 /// use the average function to compute sqrt( ((1-aver)^2 + (1-aver)^2 + (2-aver)^2 + (3-aver)^2 + (5-aver)^2 + (8-aver)^2 + (13-aver)^2) / (7-1) ) sqrt((13.79+13.79+7.36+2.93+0.08+10.79+68.65)/6) sqrt(19.57) 4.42Your method should return the standard deviation -- as a double -- when given an array of ints. (In java, you can compute the square root using Math.sqrt(num). For instance Math.sqrt(25.0) will return 5.0.)
X X XX XXX XXXXX XXXXXXXX XXXXXXXXXXXXXYou will most likely use a for loop within a for loop to so this. In Java you can print things on the same line using System.out.print. So, for instance
System.out.print("hi"); System.out.print(" there"); System.out.println(" Clara"); System.out.println(" and others");would result in
hi there Clara and others
java Utilities 1 6 2 5 3 4 The numbers entered are: 0 1 1 6 2 2 3 5 4 3 5 4 The average is: 3.5 The max is: 6 The standard deviation is: 1.87 X XXXXXX XX XXXXX XXX XXXX
You should have at least 2 files in your HW2 directory: Utilities.java, and Readme. (You might also have .class files.)
cd cd CS113 mkdir HW2Once you have made the HW2 directory in Unix, open a terminal on you own computer and in that terminal use "cd" to navigate to the directory containing your work for this assignment. Assuming you use the same directory structure on your own computer and in the lab, this process can be accomplished with the following commands
cd cd CS113 cd HW2Then use the scp command to copy each of the files you want to submit from your computer to the lab. For example:
scp Readme UNIX_NAME@goldengate.cs.brynmawr.edu:CS113/HW2/ReadmeAs always, when you read "UNIX_NAME" put in your UNIX user name. Also, with each scp command you will need to enter your UNIX password.
cd cd CS113 /home/gtowell/bin/submit -c 113 -d HW2 -p 2In response to the submit command you should see a series of messages ending with:
Submitting archive... Submission complete! Submission timestamp is 2023-08-08-15-30-28-EDT.