Assignment 5
Assignment 5
Input Result
Given a sorted array, write a java method int [] removeDuplicates(int[] array) that
removes all duplicates integers in the array. For example, an input of [0, 0, 0, 1, 1, 3, 4, 4, 4, 4, 6, 6]
should return [0, 1, 3, 4, 6]
Exercise 7: Array Character Counter
1. Create a 1D array of integers of size 26 called alphArray.
2. Ask the user to input a sentence s.
3. Write a case-insensitive function that receives the array alphArray and the sentence s and then fills
the array with the number of occurrences each English alphabet letter appears in s. Each element
in alphArray corresponds to such letter. Ignore all non-alphabet letters found in s.
4. In your solution, avoid using a set of nested if/else(s) to figure out for which alphabet letter a
certain character in s corresponds. A simple game of math does the job (can you guess what it’s?).
5. Once done, print the English alphabet letters (each on a separate line) and next to it how many
times it appears in s. Ignore any alphabet letter whose count is zero. In the example below, the
output ignores printing the alphabet letter f, j, k. p, q, u, v, x, and z since they don’t show up in s at
all.
Sample Run:
Please enter a sentence: Hello there! Today I went out to bring some groceries.
The letter count is:
a: 1
b: 1
c: 1
d: 1
e: 7
g: 2
h: 2
i: 2
l: 2
m: 1
n: 2
o: 6
r: 4
s: 2
t: 4
u: 1
w: 1
y: 1
Exercise 8- Exam Analytics
In this exercise, you will be helping professors in calculating the analytics of a given exam. The file
grades.txt stores the grades in different sections as follows: Each line represents respectively the scores
of all students in one section, for example, the first line stores the grades of section 1; the second line
contains the grades of section 2, and so on. The first number of each line represents the number of
students in the corresponding section.
1. Write a function, double calculateAverage(double[] grades), that takes an array of
doubles representing the grades, and returns the average.
2. Write a function, double[] lowestAndHighest(double[] grades), that takes an array
of doubles representing the grades, and returns the highest and the lowest grades as an array.
3. Write a function, void readGrades(String file), that takes a file name, read the file one section at a
time. For each section, the grades should be saved in an array. Then using the functions
implemented previously, it should calculate and print the analytics (average, min, and max) of every
section, in addition to the average, the lowest, and the highest grades of the whole class.
For example:
Section 1: average = 70.1, lowest = 23, highest = 91.
Section 2: average = 59.8, lowest = 32, highest =92.
…
Class: average = 68.6, lowest = 23, highest = 94