In: Computer Science
Design a solution that requests and receives student names and an exam score for each. Use one-dimensional arrays to solve this.
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 Script
Thank you
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name[] = new String[100];
Double marks[] = new Double[100];
int a =0;
do{
// Getting student name from user
name[a] = input.next();
// Getting student name from user
marks[a] = input.nextDouble();
a++;
}while(name[a] == "alldone");
//Sorting the marks using bubble sort techinique
int n = marks.length; // stores the length of the array
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (marks[j] > marks[j+1])
{
// swaping both the terms
double temp = marks[j];
marks[j] = marks[j+1];
marks[j+1] = temp;
//swapping the corresponding names
String tempStr = name[j];
name[j] = name[j+1];
name[j+1] = tempStr;
}
//after bubble sort, the highest element gets placed at the end of the array
System.out.println("The student with the highest score is "+name[n-1]+" with a score of "+marks[n-1]);
System.out.println("Sorted list");
//printing the sorted list
for(int q = 0 ;q < n ;q++)
System,out.println(name[q] + " " + marks[q]);
}
}
The code produces the following output