I have this lab I\'ve been trying to work on but I can\'t figure out how to comp
ID: 3824864 • Letter: I
Question
I have this lab I've been trying to work on but I can't figure out how to complete it. Here are all the resources provided by the instructor.
LAB07, Array of Student Class objects – Bubble Sort Points: 25
OBJECTIVE
• To demonstrate the concept of sorting
• To demonstrate the Bubble sort
• To demonstrate sorting objects
REQUIRED
A report of your work, in a flat pocket folder, in the following order:
1. Grade form Lab07GradeForm.doc
2. This program description
3. The source listing of the Student class Student.java
4. Problem Analysis with Input, Output, Pseudocode (word processed)
5. Data dictionary (included as comments in Java program
6. The listing of the source program Lab07.java
7. Listing of the input file Lab07StudentFile.txt
8. Listing of the student name file Lab07Names.txt
8. Listing of the expected results (already created) Lab07ExpectedResults.xlsx
9. Listing of the output file Lab07Report.txt
SPECIFICATIONS
Start with Lab06 and rename it as Lab07
There were two parts to Lab06:
Part1 – create an array of objects and then place values into the objects in the array
Part2 – retrieve the objects from the array and print a report
Lab07 will insert a step in between –- Sorting the array of objects
Create a Bubble Sort method and pass the array to it. Using the Bubble sort, sort the array in descending order, by average Since arrays are referenced when passed to a method, there is no need to return the array.
In order for this to work properly: Part1 must create the complete array and nothing else Then the array is sorted Part2 retrieves objects from the array and creates the report, with the student name. Therefore, the name search must be after the sort.
The report should look the same as Lab06 except it will be in descending order by average.
INPUT
File: Student file Lab07StudentFile.txt
Record: Student record
Field Data Type
Student id# 4 numbers (ex. 1234)
Ten test scores integers (valid numbers are 0 -100)
INPUT
File: Student name file Lab07Names.txt
Record: Student name record
Field Data Type
Student id# 4 numbers (ex. 1234)
Student name String
OUTPUT
File: Grade Report file Lab07Report.txt
Record:
Student Grade Report, sorted by Avg
ID# Name /----------------TEST Scores---------------/ Total Adj Total Avg
xxxx xxxxxxxxxxxxxxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx xxxx xxx
xxxx xxxxxxxxxxxxxxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx xxxx xxx
xxxx xxxxxxxxxxxxxxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx xxxx xxx
Total students = xx
Here's the link to the completed lab06 which it builds upon.--> https://pastebin.com/4cxF0YGb
Here's the link to the completed Student Class file.--> https://pastebin.com/DvZvKq2M
Explanation / Answer
import java.util.Scanner;
class StudentList {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number of students: ");
int numOfStu = input.nextInt();
int[] grades = new int[numOfStu];
String[] names = new String[numOfStu];
for (int i = 0; i < numOfStu; i++) {
String name = input.next();
int grade = input.nextInt();
names[i] = name;
grades[i] = grade;
System.out.println("");
}
//this is the area that sorts it from least to greatest
//i is the indexed value of the last number in array
//if it's 10 numbers big, i is 9
//loop ends before index 0 because 0 should be in it's place at the end already
for (int i = grades.length - 1; i > 0; i--) {
//resets both to 0 to start at the beginning of the array
//so that you can test the new first number
int currentMax = grades[0];
int currentMaxIndex = 0;
//finds largest number out of all up to back-limit
//i is back-limit that gets chopped off by one each time
for (int k = 1; k <= i; k++) {
if (currentMax < grades[k]) {
currentMax = grades[k];
currentMaxIndex = k;
}
}
//after largest number is found, assign that number to i
//i is a high number like 9, then 8, then 7, etc.
//each time it runs, i-- so each second highest max number
//gets put infront of the all time highest number
grades[currentMaxIndex] = grades[i];
grades[i] = currentMax;
String tempName = names[currentMaxIndex];
names[currentMaxIndex] = names[i];
names[i] = tempName;
}
for(int i=0; i<grades.length; i++)
System.out.println(names[i] + " " + grades[i]);
}
public static int[] reverseInt(int[] array) {
int[] poop = new int[array.length];
for (int i = 0, j = poop.length - 1; i < array.length; i++, j--) {
poop[j] = array[i];
}
return poop;
}
public static String[] reverseString(String[] array) {
String[] poop = new String[array.length];
for (int i = 0, j = poop.length - 1; i < array.length; i++, j--) {
poop[j] = array[i];
}
return poop;
}
}