**************PLEASE EXPLAIN CLEARLY***********(JAVA) Assume there is an initial
ID: 3822200 • Letter: #
Question
**************PLEASE EXPLAIN CLEARLY***********(JAVA)
Assume there is an initialized array called testScores with of size 80 with values already loaded
ExamScores Index
[0]
[1]
[2]
[3]
[4]
…
[79]
ExamScores Content
100
96
82
88
84
…
76
a. Write the following methods getTotal(): returns the integer of the total of the scores in the testScores array
b. scoresOver(int num): returns the number of scores over the given score. Example: scoresOver(90) might return a 17 which would be the number of scores over 90.
Assume all required libraries are imported
2. Write the code segment to create an integer array called numArray with a size of 100
3. Write the code segment to load numArray with random integers from 1 to 1000.
4. Write the code segments to find the sum of numArray
5. Write the code to add the number 415 to list
6. Write the code to check to see if 237 is on the list.
7. Write the code segment to declare a File object for an external file called “police.txt”, then Scanner object to read the file in that file.
8. Write the code segment to declare a File object for an external file called “dataOut.txt”, then a PrintWriter object to write to that file.
ExamScores Index
[0]
[1]
[2]
[3]
[4]
…
[79]
ExamScores Content
100
96
82
88
84
…
76
Explanation / Answer
a. public int getTotal()
{
int total = 0;
for(int i = 0; i < testScores.length; i++ )
{
total+=testScores[i];
}
return total;
}
b.
public int scoresOver(int num)
{
int count = 0;
for(int i = 0; i < testScores.length; i++ )
{
if (testScores[i] > num)
count++;
}
return count;
}
2. int[] numArray = new int[100];
3.
private static final Random randomNumbers = new Random();
for(int i = 0; i < numArray.length; i++)
{
numArray[i] = randomNumbers.nextInt(1000) + 1;
}
4.
public int getTotal(int[] numArray)
{
int total = 0;
for(int i = 0; i < numArray.length; i++ )
{
total+=numArray[i];
}
return total;
}
5. list.add(415)
6. if(list.contains(new Integer(237)))
System.out.println("Found");
7.
File file = new File("police.txt");
Scanner sc = new Scanner(file);
8.
File file1 = new File("dataOut.txt");
PrintWriter pw = new PrintWriter(file1);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.