Question: JAVA program Note: you can't change anything is already written Student.java public class Student { private String name; private String major; private double gpa; public
JAVA program
Note: you can't change anything is already written
Student.java
public class Student {
private String name; private String major; private double gpa;
public Student(String name, String major, double gpa) { // TO-DO: Assign the given parameters to the data fields. Use the this keyword. }
public double getGPA() { // TO-DO: return this.gpa }
public String getName() { // TO-DO: return this.name }
// toString method: this is a handy way to specify what you want it to look like when you // print a Student object. Without this, printing a student using System.out.println(student) // will print a memory address. The toString method is called implicitly (you don't have to // call it explicitly when you print) public String toString() { return "[" + name + ", " + major + ", " + gpa + "]"; }
}
StudentShuffle.java
/* Your Name * Date * Homework 3 StudentShuffle */
import java.util.Scanner; import java.io.*;
public class StudentShuffle {
private Student[] studentArray;
public StudentShuffle() { this.studentArray = new Student[15]; }
public Student[] getStudentArray() { return this.studentArray; }
public void getDataFromFile() { /* TO-DO: write a method to get data from the text file, store the data in * Student objects, and store the students in an array. * Suggestion: use Scanner myScanner = new Scanner(new FileReader("students_list.txt")) * to access the file. * Write your code inside the try block (you can leave the catch block as-is). * Some useful methods: Scanner hasNextLine(), String split(), Double.valueOf() */ // You may initialize some variables here try { // Your code here
} catch(FileNotFoundException e){ System.out.println(e.getMessage()); } }
public void printStudents(Student[] students) { // TO-DO: write code to print each student on a new line. // The toString method in Student class is already written, so // using system.out.println(students[i]) will print a student using my format // NOTE: you must not display null values // Your code here }
public double findLowestGPA() { // TO-DO: write a method to find the lowest GPA and return that value. // Make sure to write logic to handle null values in the array. // Hint: use the method getGPA from Student class
// Your code here
}
public Student[] getStudentsWithPerfectGPA() { // TO-DO: write code that finds the students with perfect GPA (4.0), // adds those students to a new array, and returns that array // Hint: use the method getGPA from Student class // Your code here
}
public Student[] sortAlphabetically(Student[] students) { // BONUS: write code to sort the student array alphabetically by name from A -> Z. // I suggest creating a new array so as to not modify the original (although this // is not required). // You may use any sorting algorithm, as long as you implement it yourself. // Hints: use getName() method from Student class, compareTo method. // Be sure to deal with null values in the array. // Your code here
}
public static void main(String[] args) { // TO-DO: implement your main method (see notes below)
System.out.println(" Part1 - Get data from file and print students"); System.out.println("------------------------------------------------"); // Instantiate a StudentShuffle object. // Call the method getDataFromFile() using the StudentShuffle object, // for example shuffle.getDataFromFile(). // Call shuffle.printStudents(shuffle.getStudentArray()) to print the students
System.out.println(" Part2 - Find the lowest GPA value"); System.out.println("------------------------------------------------"); // Call findLowestGPA() method, save the value returned, and print it
System.out.println(" Part3 - Find the students with highest GPA"); System.out.println("------------------------------------------------"); // Call getStudentsWithPerfectGPA() method, save the returned array, // and use your printStudents method to print the good students
System.out.println(" Part4 Bonus - Sort the students alphabetically"); System.out.println("------------------------------------------------"); // Call your sortedAlphabetically method and save the returned array. // Use your printStudents method to print the sorted array. }
}
Student_list.text
Brenna Computer_Science 4.0 Janet Biology 3.4 Sandeep Physics 3.9 Grant Marketing 4.0 Wei Business 3.7 Andre Communications 3.7 Fernanda Math 3.9 Jonas Physiology 2.9 Grace Fine_arts 3.5 Stephanie Chemistry 4.0 Mohammed Business 3.9 Nozomi Computer_Science 3.5 Aparna Literature 3.7 Ayesha Business 3.5
1- you need to get data from file
2- print the data
3- print the lowest gpa
4- print student with gpa 4.0
5- sort Alphabetically and print them
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
