Question

Design a solution that requests and receives student names and an exam score for each. Use...

Design a solution that requests and receives student names and an exam score for each. Use one-dimensional arrays to solve this.

  • The program should continue to accept names and scores until the user inputs a student whose name is “alldone”.
  • After the inputs are complete determine which student has the highest score and display that student’s name and score.
  • Finally sort the list of names and corresponding scores in ascending order.

When you are done, printout the Code and, also the corresponding output produced. Upload both the txt file and the console output showing that your program run correctly.

Sample Input:

John   69

Alex 89

Billy 72

Sam   59

Serena 96

Alldone

Sample Output:

The student with the highest score is Serena with a score of 96

Sorted list

Serena 96

Alex 89

Billy 72

John   69

Sam   59

Please Write In JAVA

Thank you

Homework Answers

Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// Students.java

import java.io.File;

import java.util.Scanner;

public class Students {

      // method to find the index of largest score in an array

      static int findMax(int scores[], int count) {

            int index = -1;

            for (int i = 0; i < count; i++) {

                  // if index is still -1 or if current score is bigger than score at

                  // index, updating index

                  if (index == -1 || scores[i] > scores[index]) {

                        index = i;

                  }

            }

            return index;

      }

      // method to sort the names and scores array

      static void sort(String names[], int scores[], int count) {

            // sorting using bubble sort algorithm

            for (int i = 0; i < count; i++) {

                  for (int j = 0; j < count - 1; j++) {

                        if (scores[j] < scores[j + 1]) {

                              // swapping elements at i and j in both names and scores

                              // arrays

                              int tmp1 = scores[j];

                              scores[j] = scores[j + 1];

                              scores[j + 1] = tmp1;

                              String tmp2 = names[j];

                              names[j] = names[j + 1];

                              names[j + 1] = tmp2;

                        }

                  }

            }

      }

      public static void main(String[] args) {

            // creating arrays to store names and scores. assuming there are no more

            // than 50 students

            String names[] = new String[50];

            int scores[] = new int[50];

            int numStudents = 0; // current number of students

            // initializing scanner to read from console. if you are reading data

            // from a file, then replace System.in with the File object, for

            // example, if you are reading from data.txt, then replace below line

            // with this => Scanner scanner = new Scanner(new File("data.txt"));

            // make sure to throw IOException, and import java.io.File;

            Scanner scanner = new Scanner(System.in);

            String name = "";

            int score;

            // looping until alldone (case insensitive) is read for name

            while (!name.equalsIgnoreCase("alldone")) {

                  //reading name

                  name = scanner.next();

                  if (!name.equalsIgnoreCase("alldone")) {

                        //reading score

                        score = scanner.nextInt();

                        //adding to arrays

                        names[numStudents] = name;

                        scores[numStudents] = score;

                        numStudents++;

                  }

            }

            //finding index of highest score

            int indexOfHighest = findMax(scores, numStudents);

            //displaying name and score of highest scorer

            if (indexOfHighest != -1) {

                  System.out.println("The student with the highest score is "

                              + names[indexOfHighest] + " with a score of "

                              + scores[indexOfHighest]);

            }

           

            //sorting and displaying sorted list

            sort(names, scores, numStudents);

            System.out.println("Sorted list");

            for (int i = 0; i < numStudents; i++) {

                  System.out.println(names[i] + "\t" + scores[i]);

            }

      }

}

/*OUTPUT (input is highlighted in bold text)*/

John   69

Alex 89

Billy 72

Sam   59

Serena 96

Alldone

The student with the highest score is Serena with a score of 96

Sorted list

Serena 96

Alex 89

Billy 72

John 69

Sam   59

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 file scores.txt (attached above) contains a list of names and test scores. Create a program...
The file scores.txt (attached above) contains a list of names and test scores. Create a program that reads each line of the file and determines the highest score and who obtained it. This is an exercise in strings. You are required to use at least one string method to determine the names and the scores. Your output should resemble the following: Highest Score: 100 Achieved by: Jay The text file looks like this: Jan 86 Drew 92 Blake 85 Alex...
You are to write a program that will process students and their grades. For each student...
You are to write a program that will process students and their grades. For each student the program will read in a student’s name. It should also read in 10 test scores for the student and calculate his or her average. You must read the scores using a loop. The program should output the student’s name, average and letter grade. The average should be displayed accurate to 1 decimal digit. Letter grades are assigned based on the scale: 90-100    A...
Below represent scores on an exam, each entry one score for one student 40 99 59...
Below represent scores on an exam, each entry one score for one student 40 99 59 98 63 63 64 65 67 35 67 67 68 70 71 71 71 46 72 72 60 73 74 74 74 75 97 75 62 76 76 76 76 76 77 57 77 98 77 63 78 78 78 79 79 80 80 80 80 80 81 81 92 81 93 82 82 83 83 83 83 83 83 83 84 84 84...
C# programming Assume we have a student final exam score lookup table like this: John 40...
C# programming Assume we have a student final exam score lookup table like this: John 40 Henry 0 Mary 59 Hillary 39 Pikachu 100 Write a class that helps check if student passes or fails the course. If a student's score is greater than or equal to a parameter passScore, we will consider it a pass. If a student's name is NOT found in the table, we assume they have missed the exam and thus consider failed. The method should...
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...
Bivariate Data & Probability After completing the calculation by hand in Q1 you can use Excel...
Bivariate Data & Probability After completing the calculation by hand in Q1 you can use Excel to check your answers before submitting. Q2 assesses your general understanding of probability and linear associations using Excel to analyse a large dataset. Question 1       Covariance and Correlation The table below shows a set of sample bivariate data. Calculate the covariance and correlation coefficient by completing the below table. Show all working. X Y (X - ) (Y - ) (X - )(Y -...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT