Create a program that keeps track of specific information for Students. The info
ID: 3831458 • Letter: C
Question
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 LinkedList. Your students should be stored in an object called Student.You must create your own linked list and cannot use the LinkedList built into Java.
You should be able to add, display, sort (by any column you chose) and remove Students in the LinkedList.
Explanation / Answer
Lab03Driver.java
import java.util.*;
import java.util.Scanner;
public class lab03Driver
{
public int index=0;
public int k=0;
public static void main(String[] args)
{
lab03Driver lab03Driver = new lab03Driver();
}
public lab03Driver()
{
Scanner in = new Scanner(System.in);
Student[] newStudent = new Student[10];
int k=0;
for(int i=0;i<=9;i++)
{
newStudent[i] = new Student();
}
while (true)
{
// Give the user a list of their options
System.out.println("1: Add a student to the class.");
System.out.println("2: Remove a student from the class.");
System.out.println("3: Display all students in the class.");
System.out.println("0: Exit the student interface.");
// Get the user input
int userChoice = in.nextInt();
switch (userChoice)
{
case 1:
addStudent(newStudent);
break;
case 2:
removeStudent(newStudent);
break;
case 3:
displayStudent(newStudent);
break;
case 0:
System.out.println("Thank you for using the student interface. See you again soon!");
System.exit(0);
}
}
}
private void addStudent(Student[] newStudent)
{
Scanner in = new Scanner(System.in);
String First_Name, Last_Name1, Major, GPA, UIN, NetID, Age, Gender,DOB,nation,city;
System.out.println("Please enter first name: ");
First_Name = in.nextLine();
System.out.println("Please enter last name: ");
Last_Name1 = in.nextLine();
System.out.println("Please enter major: ");
Major = in.nextLine();
System.out.println("Please enter GPA: ");
GPA = in.nextLine();
System.out.println("Please enter UIN: ");
UIN = in.nextLine();
System.out.println("Please enter NetID: ");
NetID = in.nextLine();
System.out.println("Please enter Age: ");
Age = in.nextLine();
System.out.println("Please enter Gender: ");
Gender = in.nextLine();
boolean student_added = false;
for(; k <newStudent.length ; k++)
{
if(newStudent[k] != null )
{
newStudent[k].createStudent (First_Name, Last_Name1, Major, GPA, UIN, NetID, Age, Gender);
index++;
student_added = true;
break;
}
}
k=index;
if (student_added)
{
System.out.println("Student Added");
System.out.println();
}
else
{
System.out.println(" Classroom is full!");
}
}
private void removeStudent(Student[] newStudent)
{
Scanner in = new Scanner(System.in);
String First_Name, Last_Name1, Major, GPA, UIN, NetID, Age, Gender, search_Last_Name;
boolean found=false;
System.out.println("Select student to remove by LAST NAME:");
search_Last_Name = in.nextLine();
for (int i = 0; i < index; i++)
{
if((newStudent[i].Last_Name).equals(search_Last_Name))
{
k=i;
found = true;
index--;
for(int j = k; j<newStudent.length-1; j++)
{
newStudent[j] = newStudent[j+1];
}
System.out.println("Student detail deleted");
break;
}
}
if(found)
{
}
else
{
System.out.println("We did not find any student by this last name");
}
}
private void displayStudent(Student[] newStudent)
{
int x=0;
for (int i = 0;i < index; i++)
{
if(newStudent[i] != null)
System.out.println(newStudent[i].toString());
else
x++;
}
if(newStudent==null)
System.out.println("NO RECORDS FOUND");
}
}
Student.java
public class Student
{
private String First_Name;
public String Last_Name;
private String Major;
private String GPA;
private String UIN;
private String NetID;
private String Age;
private String Gender;
private String DOB;
private String city ;
private String nation ;
public Student(String First_Name, String Last_Name, String Major, String GPA, String UIN, String NetID, String Age, String Gender)
{
First_Name = First_Name;
Last_Name = Last_Name;
Major = Major;
GPA = GPA;
UIN = UIN;
Age = Age;
Gender = Gender;
}
public Student()
{
}
public String getFirstName()
{
return First_Name;
}
public void setFirst_Name(String value)
{
First_Name = value;
}
public String getLastName()
{
return Last_Name;
}
public void setLast_Name(String value)
{
Last_Name = value;
}
public String getMajor()
{
return Major;
}
public void setMajor(String value)
{
Last_Name = value;
}
public String getGPA()
{
return GPA;
}
public void setGPA(String value)
{
GPA = value;
}
public String getUIN()
{
return UIN;
}
public void setUIN(String value)
{
UIN = value;
}
public String getNetID()
{
return NetID;
}
public void setNetID(String value)
{
NetID = value;
}
public String getAge()
{
return Age;
}
public void setAge(String value)
{
Age = value;
}
public String getGender()
{
return Gender;
}
public void setGender(String value)
{
Gender = value;
}
public String toString()
{
return "First Name: " + First_Name + " Last Name: " + Last_Name + " Major: " + Major + " GPA: " +GPA+ " UIN: " + UIN + " NetID: " + NetID+ " Age: " + Age+ " Gender: " + Gender;
}
public void createStudent(String first_Name2, String last_Name2, String major2, String gPA2, String uIN2, String netID2, String age2, String gender2)
{
First_Name = first_Name2;
Last_Name = last_Name2;
Major = major2;
GPA = gPA2;
UIN = uIN2;
NetID=netID2;
Age = age2;
Gender = gender2;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.