Question
import java.util.Random; import java.util.Scanner; public class ArrayTask { final int LOW = 1; final int HIGH = 100; Scanner in = new Scanner(System.in); private int
import java.util.Random; import java.util.Scanner; public class ArrayTask { final int LOW = 1; final int HIGH = 100; Scanner in = new Scanner(System.in); private int getInt() { Scanner in = new Scanner(System.in); int integer = -1; try { integer = in.nextInt(); } catch (Exception e) { System.out.println("Not an integer! Try again"); return -1; } return integer; } private void initRand(int arr[], int size) { Random rand = new Random(); for (int i = 0; i arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } private void copy(int arr1[], int arr2[], int size) { for (int i = 0; i = 0; i--) { if (count
System.out.println("All values are even"); break; case 2: boolean unique = task.isUnique(list, size); if (!unique) System.out .println("Some values/list appear multiple times"); else System.out.println("All values are unique"); break; case 3: System.out .println("The minimum gap between 2 adjacent values is " + task.minGap(list, size)); break; case 4: task.print(list, size); System.out.println("The mean for this list is: " + task.getMean(list, size)); System.out.println("The variance for this list is: " + task.getVariance(list, size)); System.out .println("The standard deviation for this list is: " + Math.sqrt(task.getVariance(list, size))); break; case 5: task.top_20(list, size); break; case 0: System.out.println("Testing completed"); System.exit(0); break; default: System.out.println("Wrong choice!"); } } while (option == -1); } } }
2. Task (reuse of code at work!): Rewrite the previous program and make it work when the list is populated with values found in an input file. The name of the file should be input from the user. Handle all possible cases (use try/catch statements). Have a constant for max size and read at most these many values from the file. Your output should be similar to the following samples: SAMPLE OUTPUT # 1: neaso input the name of the file be opened: input.tx Fil Nat. Found! Exit program! SAMPLE OUTPUT #2: For this file holding all values of unwanted types: a nd fderfd sdfgvdfS23 tdaf, asdas? ergenwr Please input thename of the ile be opened: input.txt The file doesn'contain any integers. Exit program! __ SAMPLE OUTPUT #3: For this tile holaina mixed types: 34 a SS 18 47 89 b 4S 6? S9 ab0bb 88 32 20 23 10 78 39 21 nm gntt Please input the mame of the file so he opened: input2.txt The lis. size is: 16 34 S5 18 9 6 59 88 37 0 27 10 78 39 21 Your optians are: All even values? A11 uniqe valuns? 3) Print min gap between values Statistics )Print. BO percentileStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started