Question
In the StudentArrayDemo.java, student array accept student object as parameter: find the first student object information according to s1 object, to find his/her name, id,
In the StudentArrayDemo.java, student array accept student object as parameter:
find the first student object information
according to s1 object, to find his/her name, id, gpa
if there is given student's name, we need search this name and find this student is in the student array or not
find the highest GPA from student array
Student.java
public class Student { String name; int id; double gpa; Student(String n,int id,double gpa) { this.name = n; this.id = id; this.gpa = gpa; } public String getName() { return this.name; } public int getID() { return this.id; } public double getGPA() { return this.gpa; } }
StudentArrayDemo.java
import java.util.*;
public class StudentArrayDemo {
public static void main(String[] args) {
// 1. instantiate several student object with their known name, id and gpa Student s1 = new Student("John", 11111, 3.68); Student s2 = new Student("Allen", 22222, 3.57); Student s3 = new Student("Mary", 33333, 4.0); Student s4 = new Student("Alex", 44444, 3.57);
// 2. create a student array with initial student object information Student studentArray [] = {s1,s2,s3,s4};
// 3. output the student array information for ( int index = 0; index < studentArray.length; index ++ ) { System.out.println( studentArray [index] ); }
// 4. search student information in the array, and check this fruit is in the list or not // Q1. find the first student object information
// Q2. according to s1 object, to find his/her name, id, gpa
// Q3. if there is given student's name, // we need search this name and find this student // is in the student array or not Scanner scan = new Scanner(System.in); System.out.println(" Which student you want to search from student array? "); String typeName = scan.next();
// Q4. find the highest GPA from student array
}
}
Step 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