Create a GUI for this particular project. You can use the lab 4 solution that yo
ID: 3822411 • Letter: C
Question
Create a GUI for this particular project. You can use the lab 4 solution that you’ve submitted.
Your GUI is completely up to you and should display all information that you find useful. It should be intuitive and informative.
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, sort (by any column you chose) and remove Students in the ArrayList.
Explanation / Answer
public class Student {
private String firstName;
private String lastName;
private String Major;
private String GPA;
private String UIN;
private String NetID;
private String Age;
private String Gender;
public Student(String firstName, String lastName, String major, String gPA, String uIN, String netID, String age,
String gender) {
super();
this.firstName = firstName;
this.lastName = lastName;
Major = major;
GPA = gPA;
UIN = uIN;
NetID = netID;
Age = age;
Gender = gender;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMajor() {
return Major;
}
public void setMajor(String major) {
Major = major;
}
public String getGPA() {
return GPA;
}
public void setGPA(String gPA) {
GPA = gPA;
}
public void setUIN(String uIN) {
UIN = uIN;
}
public String getNetID() {
return NetID;
}
public void setNetID(String netID) {
NetID = netID;
}
public String getAge() {
return Age;
}
public void setAge(String age) {
Age = age;
}
public String getGender() {
return Gender;
}
public void setGender(String gender) {
Gender = gender;
}
public String getUIN() {
// TODO Auto-generated method stub
return null;
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Student> newStudents = new ArrayList<Student>();
System.out.println("Welcome to the Student Interface!.");
System.out.println("Please select a number from the options below ");
while (true) {
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.");
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;
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();
if (newStudents.size() <= 10) {
newStudents.add(new Student(firstName, lastName, Major, GPA, UIN, NetID, Age, Gender));
System.out.println("Student added ");
} else {
System.out.println(" Student interface is full!");
}
private static void displayStudent(ArrayList<Student> newStudents) {
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 (((Student) 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");
}
}
}
}