Question

In an ITEC 3150 section students have just taken a test. All the test scores are...

In an ITEC 3150 section students have just taken a test. All the test scores are stored in an array. As the instructor you want to find what the highest score is on the test and how many students received that score. Write a method, topScore, that on an input array of integers representing students’ test scores, returns an integer array consisting of the highest score and the number of times it occurs. The skeleton for the method topScore is provided in the file Hw1_p3.java in the Homework Files folder.

The following is a sample run:

Input: 54 78 62 65 74 90 90 75

Return value: 90 2

Explanation: 90 is the highest score and occurs twice in the input array.

In order to receive full credit, your method must have time complexity ?(?), where ? is the length of the input array. Therefore, you do not have time to sort because sorting requires ?(?log?) time. Hint: You can go through the array a couple of times.

Note: For this problem you are NOT allowed to use a HashMap or TreeMap. If you don’t know what these are, don’t worry. We will cover them in a few weeks

public class Hw1_p3 {
  
   public static int[] topScore(int[] scores) {
       int[] ans = new int[2];
      
       // Your code starts
      
      
       // Your code ends
      
       return ans;
   }

   public static void main(String[] args) {
       // Test drive for topScore

   }

}

Homework Answers

Answer #1
public class Hw1_p3 {

    public static int[] topScore(int[] scores) {
        int[] ans = new int[2];
        // Your code starts
        int max = scores[0];
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] > max)
                max = scores[i];
        }
        ans[0] = max;
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] == max) {
                ans[1]++;
            }
        }
        // Your code ends
        return ans;
    }

    public static void main(String[] args) {
        int[] data = {54, 78, 62, 65, 74, 90, 90, 75};
        int[] result = topScore(data);
        System.out.println(result[0]);
        System.out.println(result[1]);
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The graph illustrates the distribution of test scores taken by College Algebra students. The maximum possible...
The graph illustrates the distribution of test scores taken by College Algebra students. The maximum possible score on the test was 110, while the mean score was 76 and the standard deviation was 7. 55 62 69 76 83 90 97 Distribution of Test Scores What is the approximate percentage of students who scored lower than 55 on the test? % What is the approximate percentage of students who scored between 62 and 90 on the test? % What is...
Java: A teacher has five students who have taken four tests. The teacher uses the following...
Java: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores: Test Score Letter Grade 90–100 A 80–89 B 70–79 C 60–69 D 0–59 F Write a class that uses a String array (or an ArrayList object) to hold the five students’ names, an array of five characters to hold the five students’ letter...
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total...
Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8. Java COde: import java.util.Scanner; public class SumOfExcess { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_VALS = 4; int[] testGrades...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++ 11. Write a function that will merge the contents of two sorted (ascending order) arrays of type double values, storing the result in an array out- put parameter (still in ascending order). The function shouldn’t assume that both its input parameter arrays are the same length but can assume First array 04 Second array Result array that one array doesn’t contain two copies of...
The graph illustrates the distribution of the test scores taken by College Algebra students. The maximum...
The graph illustrates the distribution of the test scores taken by College Algebra students. The maximum possible score on the test was 130, while the mean score was 79 and the standard deviation was 11. What is the approximate percentage students who scored between 68 and 90 on the test? What is the approximate percentage of students who scored between 46 and 79 on the test? What is the approximate percentage of students who scored higher than 101 on the...
Java... Write a class named TestScores. The class constructor should accept an array of test scores...
Java... Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to...
AM -vs- PM Test Scores: In my PM section of statistics there are 30 students. The...
AM -vs- PM Test Scores: In my PM section of statistics there are 30 students. The scores of Test 1 are given in the table below. The results are ordered lowest to highest to aid in answering the following questions. index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 score 43 48 50 52 55 60 61 62 64 65 66 67 68 71 75 index 16 17 18 19 20 21 22...
AM -vs- PM Test Scores: In my AM section of statistics there are 22 students. The...
AM -vs- PM Test Scores: In my AM section of statistics there are 22 students. The scores of Test 1 are given in the table below. The results are ordered lowest to highest to aid in answering the following questions. index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 score 35 50 58 59 60 61 65 66 68 68 69 74 76 76 79 82...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT