Question
using java Instructions: Write a program called RandomClassGrades.java that will create and fill a two dimensional array with integers 0-100 corresponding to grades in different
using java
Instructions: Write a program called RandomClassGrades.java that will create and fill a two dimensional array with integers 0-100 corresponding to grades in different classes. Each row (representing a different classroom) has a random size, and should be sorted in descending order. The program will search for a specific (valid) grade or a grade range as indicated by the user.
Begin by declaring a two-dimensional integer array (classGrades) that has 3 rows.
Create (set the size for) each of the one-dimensional arrays within classGrades using randomly generated integers between 15 and 40 (incl).
Overload fillArray(): define a method called fillArray two times (suggested headers follow) to fill the parameter array with random integers between 0 and 100, inclusive). It doesnt matter how you generate these random integer values.
fillArray(int[]array)
fillArray(int[][]array)
Note: for full credit here, you should only use one loop in either of the methods.
Define printArray(int[][]array): define a method called printArray to display the grades for each class in an easy to read format (with 10 elements per line.
Note: for full credit here, you may not use Arrays.toString()or Arrays.deepToString()
Overload sortArray(): define a method called sortArray two times (suggested headers follow) to sort the arrays in descending order.
sortArray(int[]arr)
sortArray(int[][]arr)
Notes:
You are not sorting the entire two dimensional array, but rather each row individually (by calling sortArray(int[]arr) with each row
for full credit here, you must implement your own sorting algorithm (either insertion or selection) in the first version (aka you may not use Arrays.sort())
Overload searchArray(): define a method called searchArray two times (suggested headers follow) to search an array for the provided key
searchArray(int[]arr, int key): must use binary search
searchArray(int[][]arr, int key): must use linear search
Use the main method to do the following (leveraging the methods above):
Create the two-dimensional with random row sizes
Use fillArray(int[][]array)to fill the two dimensional array with random integer values
Use printArray(int[][]array)to display the unsorted random grades
Call sortArray(int[][]arr) to sort each row of the two dimensional array
Use printArray(int[][]array)to display the sorted random grades
Display the average grade for each class (row) as well as for all three classes (the entire array) to 3 decimal places.
Prompt the user to enter either an integer representing a specific score to search for in the list, or a character representing a letter grade range. >>> If the user types an invalid option, keep prompting until they choose a valid one (either integer 0-100 or A,B,C,D,F)
If the user enters an integer, use binary search to find the entered grade in each of the classes separately. Indicate if the grade was found or not in each class.
Make sure the integer entered is within the valid grade range (0-100) (reprompt if not)
If the user enters A, B, C, D, F: use linear search to identify and display the number of occurrences of scores in the specified grade letter range across all three sections.
If the user types A, you should return the number of scores from the entire array (all three classes) that are within the A range (identified below).
For example, assume that:
Scores between 90 and 100 represent As
Scores between 80 and 89 represent Bs
Scores between 70 and 79 represent Cs
Scores between 60 and 69 represent Ds
Scores between 0 and 59 represent Fs.
If the user types anything else, reprompt them for valid input (either an int between 0 and 100 or chars A, B, C, D, F).
Sample output :
Class 1: 75 25 19 85 63 64 25 45 49 95 23 85 69 8 97 49 58 8 58 13
Class 2: 43 71 15 48 96 15 61 60 45 66 92 61 76 30 48 2 55 48 5 73 87 51 100 87 38 87 44 89 50 25 62 38 80 90 62 87
Class 3: 29 42 13 26 90 26 62 59 64 78 47 36 22 19 29 42 47 5 65 87 89 97 63 58 64 48 90 4 39 32 70 17 57 43 22 57 50 14 42
Sorting...
Class 1: 97 95 85 85 75 69 64 63 58 58 49 49 45 25 25 23 19 13 8 8
Class 2: 100 96 92 90 89 87 87 87 87 80 76 73 71 66 62 62 61 61 60 55 51 50 48 48 48 45 44 43 38 38 30 25 15 15 5 2
Class 3: 97 90 90 89 87 78 70 65 64 64 63 62 59 58 57 57 50 48 47 47 43 42 42 42 39 36 32 29 29 26 26 22 22 19 17 14 13 5 4
Enter a letter grade or specific score
A
Number of As in all three classes: 9
Alternate run:
Class 1: 81 53 59 9 47 36 23 38 42 5 53 22 72 52 75 52 73 63 50 68 87 62 100 53 98 72 0 83 70 96 42 75 9 31 94 34 11 30
Class 2: 60 70 43 69 8 22 83 80 49 25 92 75 73 7 96 56 74 100 19 23 81 53 3 36 76 73 30 34 62 90 45
Class 3: 23 39 37 3 76 79 57 14 90 38 1 93 6 94 74 8 20 87
Sorting...
Class 1: 100 98 96 94 87 83 81 75 75 73 72 72 70 68 63 62 59 53 53 53 52 52 50 47 42 42 38 36 34 31 30 23 22 11 9 9 5 0
Class 2: 100 96 92 90 83 81 80 76 75 74 73 73 70 69 62 60 56 53 49 45 43 36 34 30 25 23 22 19 8 7 3
Class 3: 94 93 90 87 79 76 74 57 39 38 37 23 20 14 8 6 3 1
Enter a letter grade or specific score
81
Running Binary Search on Class 1
81 found in Class 1 at index=6
Running Binary Search on Class 2
81 found in Class 2 at index=5
Running Binary Search on Class 3
81 not found in Class 3
Assignment: Answer the following questions without writing any code on your computer. Write your solutions in the space provided and submit your completed work as a single pdf. Name this file Lab8Comp.pdf.
Given the array list1 below, how many comparisons are performed when running a linear search for the character !?
char[] list1 ={A, Z, -, r, b, Q, l, H, w, o, 3};
With very large, sorted arrays, we know binary search is often the better choice over linear search. However, there are times when linear search is more efficient. Describe an instance when you would want to use linear search over binary search.
Consider the array list2 below. Assume we randomly scrambled it 9,234,765 times. After each scramble, we use a linear search to find the character a. On average, how many comparisons occur during each search?
char[] list2 ={c, $, e, R, 0, C, k, $, !, h, U};
Again consider the same array list2 from part (b), but put into sorted order (based on unicode value). How many comparisons (to the middle element) would be performed when running a binary search for the character !? When determining the middle index, recall that Java truncates any decimal places when doing integer division.
Step 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