Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a java program that sorts the following students. do not use array sort m

ID: 3627539 • Letter: C

Question

Create a java program that sorts the following students. do not use array sort method.

NOTES:
Sort from lowest score to highest score.
You must have at least three unique methods other than the main method
A method to enter student name and scores.
A method to sort students by scores.
A method to print the sorted student results.

Sample:

Enter the number of students: 3
Enter a student name: Smith
Enter a student score: 70.0
Enter a student name: Jones
Enter a student score: 30.0
Enter a student name: Peterson
Enter a student score: 100.0
Jones 30.0
Smith 70.0
Peterson 100.0

Explanation / Answer

/*
Hi, I have seen that you've asked this question here(http://www.cramster.com/answers-jul-11/computer-science/array-question-notessort-lowest-score-highest-scoreyou_1398435.aspx?rec=0), so I have converted the answer to Java. This program has been tested and works before being posted.
-B
*/

package test;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int SIZE;
double scores[] = new double[30];
String names[] = new String[30];

System.out.println("Enter the number of students: ");
SIZE = in.nextInt();
inputData(names, scores, SIZE);

System.out.println("The unsorted values are");
showArray(names, scores, SIZE);
selectionSort(names, scores, SIZE);

System.out.println("The sorted values are");
showArray(names, scores, SIZE);
}

public static void inputData(String names[], double scores[], int SIZE) {
Scanner in = new Scanner(System.in);
for (int i = 0; i < SIZE; i++) {
System.out.print("Enter a student name: ");
names[i] = in.next();
System.out.print("Enter a student score: ");
scores[i] = in.nextDouble();
}
}

public static void selectionSort(String names[], double scores[], int size) {
int startScan, minIndex;
double minValue;
String str;
for (startScan = 0; startScan < (size - 1); startScan++) {
minIndex = startScan;
str = names[startScan];
minValue = scores[startScan];
for (int index = startScan + 1; index < size; index++) {
if (scores[index] > minValue) {
str = names[index];
minValue = scores[index];
minIndex = index;
}
}
names[minIndex] = names[startScan];
scores[minIndex] = scores[startScan];
scores[startScan] = minValue;
names[startScan] = str;
}
}

public static void showArray(String names[], double array[], int size) {
System.out.println( "Names Scores");
for (int i = 0; i < size; i++) {
System.out.println(names[i] + " " + array[i]);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote