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

Create a GUI for this particular project. You can use the lab 4 solution that yo

ID: 3859879 • 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.

Hint: To make your life easier take your previous lab solution and add a menu bar instead of adding a lot of new items.

Here is my lab 4 code:

import java.util.*;

public class Lab4
{
//Main method
public static void main(String[] args)
{
//Array list
ArrayList<Student> students = new ArrayList<Student>();
  
int option;
  
//Iterate till user wants to quit
while(true)
{
//Displaying menu
option = menu();
  
//Calling corresponding functions
switch(option)
{
//Add Student
case 1: addStudent(students); break;
  
//Display Student
case 2: displayStudent(students); break;
  
//Remove Student
case 3: removeStudent(students); break;
  
//Quit
case 4: return;
  
default: System.out.println(" Invalid option "); break;
  
}
}
}
  
public static int menu()
{
int ch;
  
//Scanner class object
Scanner reader = new Scanner(System.in);
  
//Displaying menu
System.out.print(" 1 - Add Student 2 - Display Student 3 - Remove Student 4 - Quit Your choice: ");
  
//Reading menu option
ch = reader.nextInt();
  
return ch;
}
  
//Method that adds a student
public static void addStudent(ArrayList<Student> students)
{
//Scanner class object
Scanner reader = new Scanner(System.in);
  
//Prompting user for data
System.out.println(" Enter student info(FirstName LastName Major GPA UIN NetID Age Gender): ");
  
//Creating a temporary student object
Student temp = new Student();
  
//Adding data
temp.setFirstName(reader.next());
temp.setLastName(reader.next());
temp.setMajor(reader.next());
temp.setGPA(reader.nextDouble());
temp.setUIN(reader.next());
temp.setNetID(reader.next());
temp.setAge(reader.nextInt());
temp.setGender(reader.next());
  
//Adding to array list
students.add(temp);
  
System.out.println(" Student Successfully added... ");
}
  
//Method that displays student
public static void displayStudent(ArrayList<Student> students)
{
System.out.println(" Students Available... ");
  
//Iterating over student data
for(int i=0; i<students.size(); i++)
{
//Printing student info
System.out.println(students.get(i));
}
}
  
//Method that removes student
public static void removeStudent(ArrayList<Student> students)
{
String name;
  
//Scanner class object
Scanner reader = new Scanner(System.in);
  
//Reading student first name
System.out.println(" Enter student FirstName to remove: ");
name = reader.nextLine();
  
int pos = -1;
  
//Iterating over student data
for(int i=0; i<students.size(); i++)
{
//Searching for given first name
if((students.get(i).getFirstName()).equalsIgnoreCase(name))
{
//Updating position
pos = i;
}
  
//If student not found
if(pos == -1)
{
System.out.println(" Sorry!!! No student exists with given name... ");
}
else
{
//Removing from array list
students.remove(pos);
System.out.println(" Successfully Removed " + name + "... ");
}
}
}
}

public class Student {
  
//Private member variables
private String FirstName;
private String LastName;
private String Major;
private double GPA;
private String UIN;
private String NetID;
private int Age;
private String Gender;

//Constructor that assigns default values
public Student() {
this.FirstName = "";
this.LastName = "";
this.Major = "";
this.GPA = 0;
this.UIN = "";
this.NetID = "";
this.Age = 0;
this.Gender = "";
}
  
//Constructor that assigns values
public Student(String FirstName, String LastName, String Major, double GPA, String UIN, String NetID, int Age, String Gender) {
this.FirstName = FirstName;
this.LastName = LastName;
this.Major = Major;
this.GPA = GPA;
this.UIN = UIN;
this.NetID = NetID;
this.Age = Age;
this.Gender = Gender;
}

//Getter for first name
public String getFirstName() {
return FirstName;
}

//setter for first name
public void setFirstName(String FirstName) {
this.FirstName = FirstName;
}

//Getter for last name
public String getLastName() {
return LastName;
}

//Setter for last name
public void setLastName(String LastName) {
this.LastName = LastName;
}

//Getter for major
public String getMajor() {
return Major;
}

//Setter for major
public void setMajor(String Major) {
this.Major = Major;
}

//Getter for GPA
public double getGPA() {
return GPA;
}

//Setter for GPA
public void setGPA(double GPA) {
this.GPA = GPA;
}

//Getter for UIN
public String getUIN() {
return UIN;
}

//Setter for UIN
public void setUIN(String UIN) {
this.UIN = UIN;
}

//Getter for NetID
public String getNetID() {
return NetID;
}

//Setter for NetID
public void setNetID(String NetID) {
this.NetID = NetID;
}

//Getter for age
public int getAge() {
return Age;
}

//Setter for age
public void setAge(int Age) {
this.Age = Age;
}

//Getter for gender
public String getGender() {
return Gender;
}

//Setter for gender
public void setGender(String Gender) {
this.Gender = Gender;
}

//Tostring method
@Override
public String toString() {
return "Student{" + "FirstName=" + FirstName + ", LastName=" + LastName + ", Major=" + Major + ", GPA=" + GPA + ", UIN=" + UIN + ", NetID=" + NetID + ", Age=" + Age + ", Gender=" + Gender + '}';
}
}

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");

}

}

}

}