Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 : image text in transcribed

a A Problems @ Javadoc Declaration & Console X Driver (1) [Java Application] C:\Program Files\Java\jdk-15.0.1\bin\javaw.exe (Feb 7, 2021, 5:20:33 PM - 5:21:08 PM) [Student@4f3f5b24, Student@4f3f5b24, Student@4f3f5b24, Student@4f3f5b24, Student@4f3f5b24] Please enter the student's first name: Please enter the student's last name: a Please enter the student's GPA: 3.7 Please enter the student's first name: b Please enter the student's last name: b Please enter the student's GPA: 2.1 Please enter the student's first name: C Please enter the student's last name: Please enter the student's GPA: 3.0 Please enter the student's first name: d Please enter the student's last name: d Please enter the student's GPA: 1.9 Please enter the student's first name: e Please enter the student's last name: e Please enter the student's GPA: 3.8 [Student@56480cf9, Student@6f496d9f, Student@723279cf, Student@10f87f48, Student@b4c966a] e e has the highest GPA of 3.8 dd has the lowest GPA of 1.9 The average GPA is: 2.9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Describe the steps in creating a decision table.

Answered: 1 week ago