I am given a .txt file of columns of students. Each row contains last name, first name, major, credits completed, and gpa. I need to create a scanner to read from a file, create a printWriter to write to a file. I have the most useless textbook I bought for the class so I pretty much have to learn this on my own. Can someone help me finish this skeleton class?
Here is my txt file:
Bunker John Computer Science 42 3.14
Smith Jane Health Education 32 3.29
Wilson Robert Community Health 61 2.3
Clinton Alice Urban Studies 45 2.9
Podesta Stephanie Biology 92 2.8
Cronk Anthony Psychology 70 1.9
Smith Matthew History 33 1.2
Appletree Joshua Communication Sciences 40 3.4
Lucas Jill Criminal Justice 56 3.8
Sanders George Elementary Education 102 2.1
O'Brien William Nursing 99 3.2
Newman Lorraine Geography 40 3.1
Meszaros Mark International Business 56 3.9
Sedaris Sharon Environmental Sciences 78 3.5
Cormier Elizabeth Neuro Science 45 3.6
Peterson Nina Cognitive Science 73 4.0
Wilson Anna Chemistry 82 3.87
here is my main method:
import java.util.Scanner; import java.io.*; /** * @author Aparna Mahadev * @version 1 - Lab10 Skeleton */ public class Lab10 { public static void main (String[] args) throws IOException { // Create a scanner to read from the file // TO BE COMPLETED BY THE STUDENT // create a PrintWriter to write to a file // TO BE COMPLETED BY THE STUDENT Student [] collection = createArrayFromFile(inFile); // Print out name of each student using a for-each loop out.println("Here is the original list"); out.println("-------------------------\n"); // TO BE COMPLETED BY THE STUDENT out.println("\n\nAfter sorting here is the list"); out.println("------------------------------\n"); sort(collection); // Print out name of each student using a for-each loop // TO BE COMPLETED BY THE STUDENT out.println("\n\nThe lowest GPA among all students is " + findMinGPA(collection, 0, collection.length - 1)); out.println("\n\nThe highest GPA among all students is " + findMaxGPA(collection, 0, collection.length - 1)); inFile.close(); out.close(); } /** * Reads one line at a time from inFile; * Uses substrging method of String class to parse * the line into first name, last name, majors, * credits completed and gpa. * Creates a Student object and adds it an array * Returns the array with exactly the number of Students * read * @param inFile input file stream * @return an array of Students whose length is exactly the number of * students read */ public static Student [] createArrayFromFile(Scanner inFile) { // TO BE COMPLETED BY THE STUDENT } /** * Sorts the Student array in the increasing order * of lastName field. * Uses compareTo method of the Student class to * compare two student objects * @param list An array of Students to be sorted */ public static void sort(Student [] list) { // TO BE COMPLETED BY THE STUDENT } /** * Finds the minimum GPA in the array recursively * Hint: use Math.min method * * @param list An array of Students * @param startIndex the beginning index of the array * @param endIndex the end index of the array * * @return The minimum GPA of all the students in the array */ public static double findMinGPA(Student[] list, int startIndex, int endIndex) { // TO BE COMPLETED BY THE STUDENT } /** * Finds the maximum GPA in the array recursively * Hint: use Math.max method * * @param list An array of Students * @param startIndex the beginning index of the array * @param endIndex the end index of the array * * @return The maximum GPA of all the students in the array */ public static double findMaxGPA(Student[] list, int startIndex, int endIndex) { // TO BE COMPLETED BY THE STUDENT } }
can someone please just walk me through this? I'm a beginner so if you try to use crazy lingo on me or if you're just extremely broad I might as well just use my textbook.