CSI2300 - Winter 2020Due Noon @Jan 23Lab01 Overview Your first lab asks to create a well-commented java project that will contain a class called Lab_01_ArrayUtilitties {...} with the following two...

java


CSI2300 - Winter 2020Due Noon @Jan 23Lab01 Overview Your first lab asks to create a well-commented java project that will contain a class called Lab_01_ArrayUtilitties {...} with the following two static methods: buildArray {...} and swap {...}. Also include in your project a class called Lab_01_Tester {...} and include the main {...} method. You have until Thursday at noon to complete this assignment. Write the following code for the ArrayUtilities class methods: 1. buildIntArray(int length, int fromNum, int toNum) a. The buildingArray() method should accept three parameters: 1) An array element length, 2) a "from number", 3) and a "to number" so that if a call to this method looked like: buildIntArray(20,5,30) an array of 20 random numbers between, and including, 5 and 30 would be returned. 2. swap(int [] nums, int i, int j) a. The swap() method will accept three parameters: 1) An int array; and 2) two variables that will represent the indices of the array whose values should be swapped. Due to the fact that java passes arrays by reference, anything you do to the array within the swap() method changes the original array. Your Lab_01_Tester's main() method should do the following: 1. Array and File I/O · Create a file (through code) called "Lab_01_nums.txt". · Hint: PrintWriter PW = new PrintWriter(new File("Lab_01_nums.txt")); · Use your method created in your ArrayUtilities class to create a 20 elements array of random integers from 10 to 29. Note, in order to use this method, you need to include the full class path: Lab_01_ArrayUtilities.buildIntArray(...) · Print the list of that array's values onto the screen AND save it to the text file. Output should look like the example given in the next page. Consider using the toString method of the Array's class: Array.toString(...) - https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html - toString(int []) · Using a loop and the swap() method, swap the value of even indexed elements with the next element in the array. That is, swap the (value in) element[0] with the (value in) element [1], element[2] with element[3], and so on. Be careful when you reach the end of the array and try for Arrays of various sizes (even and odd sized arrays). · Print the list of array values to screen again and append it to the text file. · Sort the array using Arrays.sort(int array) https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html - sort(int[]) · Print the list of array values again and append it to the text file · Close the file 2. Odd Numbers · Iterate through the created array of numbers from above and count the number of add values. · Print the output to the user with a understandable description. 3. Vowels, Consonants, and Other characters · Manually create a text file in the root workspace folder called words.txt and include the following lines: apple banana grapes · Write the code that opens the file, reads each line, and counts the number of vowels(A,E,I,O,U), consonants, and other characters. · Hint: Scanner in = new Scanner (new File("words.txt")); · while(in.hasNext()){...} · Hint: To determine if a character is an "other" character, you can start by determining if the specific character is or is not a letter. The isLetter method of the Character class might be helpful. · It is specially helpful if you are scanning character by character, is the Character.isWhitespace method. · Using the println() function to format your output display a message to the user with the results. (you should get, 7 vowels, 10 consonants, and 0 other characters) · I will be testing your class using my own words.txt file so be sure to cover ALL scenarios of possible text data. DO NOT submit or create a words.txt file! Sample Console and Text File Output: Grading Rubric Late submission - 0/30 pts 1. 5 pts - correct file names, method names, commented code, compiles, proper turn-in 2. 10 pts - (1) buildIntArray() and (2) swap () methods are free from coding errors and written well. I. (1) method returns an int array of random values which also includes fromNum and toNum II. (2) method is void and correctly swaps two elements from the array 3. 15 pts - main method code is free from coding errors and written well. I. Uses PrintWriter() to write data to the file: Lab_01_nums.txt II. Data is printed to the console like my example III. A loop is used to swap every other adjacent elements of array Turn-In Process Turn in a .zip of your "src" folder containing your two .java files to Moodle by the respective due date and time shown above. ENSURE THAT YOU TURN IN .java files only in the zip and they compile. No late assignment will be accepted. Grading will be based on conforming to the standards and styles we proposed in class as well as following the requirements of this lab.
Jan 21, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here