Question
I have two java class public class Student { public String firstName = ; public String lastName = ; public double gpa; public Student() {
I have two java class public class Student { public String firstName = ""; public String lastName = ""; public double gpa; public Student() { firstName = ""; lastName = ""; gpa = 0.0; } public Student(String firstName, String lastName, double gpa) { this.firstName = firstName; this.lastName = lastName; this.gpa = gpa; } } second is ============
import java.util.InputMismatchException; import java.util.Scanner; import java.util.Arrays;
public class Driver { private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
Student[] myClass = new Student[5]; Arrays.fill(myClass, new Student()); System.out.println(Arrays.toString(myClass));
for (int i = 0; i
int highestGpa = findMaxGpa(myClass); System.out.println(myClass[highestGpa].firstName + " " + myClass[highestGpa].lastName + " has the highest GPA of " + myClass[highestGpa].gpa);
int lowestGpa = findMinGpa(myClass); System.out.println(myClass[lowestGpa].firstName + " " + myClass[lowestGpa].lastName + " has the lowest GPA of " + myClass[lowestGpa].gpa);
System.out.println("The average GPA is: " + averageGpa(myClass));
scanner.close(); }
private static void getStudentInfo(Student[] students, int index) { String firstName; String lastName; double gpa;
do { System.out.print("Please enter your First Name: "); firstName = scanner.nextLine(); } while (firstName.isEmpty() == true);
do { System.out.print("Please enter your Last Name: "); lastName = scanner.nextLine(); } while (lastName.isEmpty() == true);
do { System.out.print("Please enter a number between 0 and 4: "); try { gpa = scanner.nextDouble(); scanner.nextLine(); } catch (InputMismatchException e) { System.out.println("Enter only number"); scanner.nextLine(); gpa = -1; } } while ((gpa == -1) || (gpa > 4) || (gpa
/* * firstNames[index] = firstName; lastNames[index] = lastName; gpas[index] = * gpa; */
Student newStudent = new Student(firstName, lastName, gpa);
students[index].firstName = newStudent.firstName; students[index].lastName = newStudent.lastName; students[index].gpa = newStudent.gpa;
}
private static int findMaxGpa(Student[] students) { double largestSoFar = -1.0; int lsfIndex = -1; for (int i = 0; i = largestSoFar) { System.out.println(students[i].gpa); largestSoFar = students[i].gpa; lsfIndex = i; } } return lsfIndex; }
private static int findMinGpa(Student[] students) { double smallestSoFar = 5.0; int ssfIndex = -1;
for (int i = 0; i
return ssfIndex; }
private static double averageGpa(Student[] students) { int count = 0; double sum = 0.0;
for (Student student : students) { count++; sum += student.gpa; }
return sum / count; }
} Output should be :
a A Problems @ Javadoc Declaration & Console XStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started