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

HW1 (Graded out of 100) Write a program that manages students\' information. Eac

ID: 3877445 • Letter: H

Question

HW1 (Graded out of 100) Write a program that manages students' information. Each student's information consists of a netID and a GPA, maintained in parallel arrays. The program will loop on displaying the following menu of choices: 1. List the top n students 2. Search for a student 3. Exit the program. If the user chooses 1, the user will be prompted for the value of n, and the netID and GPA of the top n students will be listed, starting with the student with highest GPA and going down. If the user chooses 2, user will be prompted to enter the student's netlD. If the netlD is found in the netlD array, the array index and the GPA of the student are displayed. If the student is not found, a "Student not found" message is displayed.

Explanation / Answer

import java.util.ArrayList;
import java.util.Scanner;

/*Create a program that keeps track of specific information for Students. The information stored should be the following:
First Name, Last Name, Major, GPA, UIN, NetID, Age, Gender,
For this simple program we will only need to store 10 students in an ArrayList.
Your students should be stored in an object called Student.
You should be able to add, display and remove Students in the ArrayList.
You will submit 2 files for grading: Lab4.java and Student.java*/

public class Lab4 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
ArrayList<Student> newStudents = new ArrayList<Student>();
// ArrayList<Student> newStudents = new ArrayList<Student>(10); tried this as well, but doesn't work.

System.out.println("Welcome to the Student Interface!.");
System.out.println("Please select a number from the options below ");

while (true) {
// Give the user a list of their options
System.out.println("1: Add a student to the list.");
System.out.println("2: Remove a student from the list.");
System.out.println("3: Display all students in the list.");
System.out.println("0: Exit the student interface.");

// Get the user input

int userChoice = input.nextInt();
switch (userChoice) {
case 1:
addStudents(newStudents);
break;
case 2:
removeStudent(newStudents);
break;
case 3:
displayStudent(newStudents);
break;
case 0:
System.out.println("Thank you for using the student interface. See you again soon!");
System.exit(0);
}
}
}

public static void addStudents(ArrayList<Student> newStudents) {

Scanner input = new Scanner(System.in);
boolean student_added = false;
// TODO: Add a student that is specified by the user

System.out.println("Please enter first name: ");
String firstName = input.next();
System.out.println("Please enter last name: ");
String lastName = input.next();
System.out.println("Please enter major: ");
String Major = input.next();
System.out.println("Please enter GPA: ");
String GPA = input.next();
System.out.println("Please enter UIN: ");
String UIN = input.next();
System.out.println("Please enter NetID: ");
String NetID = input.next();
System.out.println("Please enter Age: ");
String Age = input.next();
System.out.println("Please enter Gender: ");
String Gender = input.next();

for (int i = 1; i < 5; i++) { // ( I have also tried i<newStudents.size(). Didn't work.Thank you in advance!)
newStudents.add(new Student(firstName, lastName, Major, GPA, UIN, NetID, Age, Gender));
student_added = true;
break;
}

if (student_added) {
System.out.println("Student Added");
System.out.println();

} else {

System.out.println(" Student Interface is full!");

}

}

private static void displayStudent(ArrayList<Student> newStudents) {
// TODO Auto-generated method stub

for (Student e : newStudents) {
System.out.println(e);
}
}

private static void removeStudent(ArrayList<Student> newStudents) {
Scanner input = new Scanner(System.in);

System.out.println("Please, enter the UIN to remove the Student: ");
String uin = input.nextLine();

for (Student e : newStudents) {
if (e.getUIN().equals(uin)) {
newStudents.remove(e);
System.out.println("Student removed");
break;
}

else {
System.out.println("Sorry, no such student with this " + uin + " " + "number exist");

}

}

}

}