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 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.

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

public class Main
{
   public static void main(String args[])
   {
       int[] scores = new int[] { 54, 78, 62, 65, 74,90,90,75};
int[] out =new int[2];
  
       out[0]=scores[0];
       for(int i = 1; i < scores.length;i++)
       {
           if(scores[i] >out[0])
           {
               out[0] = scores[i];
           }
          
       }
      
   out[1]=0;
       for(int i = 0; i < scores.length;i++)
       {
           if(scores[i]==out[0])
           out[1]=out[1]+1;
           }
      
       System.out.println("The Highest score is:" + out[0]);
       System.out.println("No of students received the highest score is:" + out[1]);
   }
}

Output:

The Highest score is:90

No of students received the highest score is:2

Add a comment
Know the answer?
Add Answer to:
In an ITEC 3150 section students have just taken a test. All the test scores are...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • C++ program that reads students' names followed by their test scores (5 scores) from the given...

    C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...

  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

  • 1) (10 pts) A class has n students, and the ith student has taken si tests....

    1) (10 pts) A class has n students, and the ith student has taken si tests. This information is stored in a file where the first line has the value of n and the following n lines have information about each student. On the ith of these lines, the first value is si. This is followed by si integers, all in between 0 and 100, inclusive, representing the test scores. Here is a sample file: 4 10 100 80 90...

  • This program should test the running time of these algorithms: Selection Sort Insertion Sort Bubble Sort...

    This program should test the running time of these algorithms: Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort Heap Sort You have access to the implementation of all of these sorting algorithms, and you may use what is provided in your text directly. Be sure to cite the source of these implementations in the header of your program. Please maintain the property that these sorting algorithms sort arrays in ascending order. For this homework, you will write a...

  • codeblock c++ language Write a program that reads students test scores in the range 0-200 from...

    codeblock c++ language Write a program that reads students test scores in the range 0-200 from a file until end of file (use e of() to check if ifstream reaches the End of File Stream) and store those scores in an array. It should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100- 124, 125–149, 150-174, and 175–200. Finally, the program outputs the total number of students, each score range...

  • In C++ language, implement a class that can sort an array of numbers using all three...

    In C++ language, implement a class that can sort an array of numbers using all three algorithms we have seen in this course, but each method updates a “counter” value every time it accesses the array. Have it print this at the end of the sorting process. Store the array values in an “original” array so you don’t have to re-type it for different sorts (since each sort alters the array), and have the sort modify a copy. Note: IF...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT