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,
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.
This is the code I have, when I run the program, it prompts me to add 10 students. How do I make it so I can add, display, sort and remove students in the LinkedList?
import java.util.*;
class Student { String firstName, lastName, major, gender; double gpa; int UIN, netId, age; Student next; Student() { firstName = ""; lastName = ""; major = ""; gpa = 0.0; UIN = 0; netId = 0; age = 0; gender = ""; next = null; } Student(Student nextStudent) { firstName = ""; lastName = ""; major = ""; gpa = 0.0; UIN = 0; netId = 0; age = 0; gender = ""; next = nextStudent; } Student(String fname, String lname, String mjr, double gpaScore, int UINval, int netIdVal, int ageVal, String gndr, Student nextStudent) { firstName = fname; lastName = lname; major = mjr; gpa = gpaScore; UIN = UINval; netId = netIdVal; age = ageVal; gender = gndr; next = nextStudent; } void getData(Scanner sc) { System.out.print("\tEnter the first name: "); firstName = sc.nextLine(); System.out.print("\tEnter the last name: "); lastName = sc.nextLine(); System.out.print("\tEnter major: "); major = sc.nextLine(); System.out.print("\tEnter gpa: "); gpa = sc.nextDouble(); sc.nextLine(); System.out.print("\tEnter UIN: "); UIN = sc.nextInt(); sc.nextLine(); System.out.print("\tEnter NetId: "); netId = sc.nextInt(); sc.nextLine(); System.out.print("\tEnter age: "); age = sc.nextInt(); sc.nextLine(); System.out.print("\tEnter gender: "); gender = sc.nextLine(); } void display() { System.out.println("Student Details:"); System.out.println("First Name:" + firstName); System.out.println("Last Name:" + lastName); System.out.println("Major:" + major); System.out.println("GPA:" + gpa); System.out.println("UIN:" + UIN); System.out.println("NetID:" + netId); System.out.println("Age:" + age); System.out.println("Gender:" + gender); System.out.println(); } };
public class Main { public static void main(String args[]) { Student head = new Student(); Scanner sc = new Scanner(System.in); int size = 0; for(int i = 0; i < 10; i++) { System.out.println("Enter details for student " + (i + 1)); if(size == 0) { head = new Student(null); } else { head = new Student(head); } size++; head.getData(sc); } for(int i = 0; i < 10; i++) { System.out.println(" Details for student" + (i + 1)); head.display(); head = head.next; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started