Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming Write a program that reads in a student file and creates Studen

ID: 3911285 • Letter: J

Question

Java Programming

Write a program that reads in a student file and creates Student.java objects with the following fields: first name, last name, GPA, and student ID. The objects will be stored in an array of Students in a class named StudentSearcher.java. Provide the user with a list of possible student IDs to search from (use an initialization list, for example, double[] salaries = {6.25, 6.55, 10.25, 16.85}; to populate the array, for the first and last name, GPA and student ID and PLEASE do not use a separate file like "studentsdata.txt" containing student data). When a user enters in a student ID, the program will search the array and display the found student's GPA. The program will continue to search students until the user exits the program.

Explanation / Answer

import java.util.Scanner;

class Student

{

private String fname;

private String lname;

private double GPA;

private String id;

public Student(String fname, String lname, double gPA, String id)

{

this.fname = fname;

this.lname = lname;

GPA = gPA;

this.id = id;

}

public String getFname() {

return fname;

}

public String getLname() {

return lname;

}

public double getGPA() {

return GPA;

}

public String getId() {

return id;

}

}

public class StudentSearcher

{

public static void main(String[] args)

{

int n;

Scanner in =new Scanner(System.in);

System.out.println("Enter the number of students");

n=in.nextInt();

Student[] arr=new Student[n];

//assuming the Student array is initialized

String s="";

while(!s.equals("N"))

{

System.out.println("Enter the ID you want to search for("N" to quit): ");

s=in.next();

if(s.equals("N"))break;

for(Student stud: arr)

if(stud.getId().equals(s))

{

System.out.println("GPA: "+stud.getGPA());

break;

}

}

in.close();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote