Working on a program that keeps track of specific information for Students. I ne
ID: 3831196 • Letter: W
Question
Working on a program that keeps track of specific information for Students. I need to store the following First Name, Last Name, Major, GPA, UIN, NetID, Age, Gender
It needs to be simple and store only 10 students in a Linked List.
All students must be stored in an object called Student (I have provided my existing Student Code below)
The LinkedList built into Java cannot be used for this, you must create your own.
Once complete you must be able to add, display and sort (by any column you chose) and remove Students in the Linked List
======================
Student Class defined completely
======================
public class Students {
// instance variable
private String firstName;
private String lastName;
private String major;
private double gpa;
private String uin;
private String netID;
private int age;
private String gender;
public Students() {
}
public Students(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;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getMajor() {
return major;
}
public double getGpa() {
return gpa;
}
public String getUin() {
return uin;
}
public String getNetID() {
return netID;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setMajor(String major) {
this.major = major;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public void setUin(String uin) {
this.uin = uin;
}
public void setNetID(String netID) {
this.netID = netID;
}
public void setAge(int age) {
this.age = age;
}
public void setGender(String gender) {
this.gender = gender;
}
Explanation / Answer
import java.util.Scanner;
class Node
{
protected int data;
protected Node link;
Constructor
public Node()
{
link = null;
data = 0;
}
Constructor
public Node(int d,Node n)
{
data = d;
link = n;
}
// Function to set link to next Node
public void setLink(Node n)
{
link = n;
}
// Function to set data to current Node
public void setData(int d)
{
data = d;
}
// Function to get link to next node
public Node getLink()
{
return link;
}
// Function to get data from current Node
public int getData()
{
return data;
}
}
class linkedList
{
protected Node start;
public int size;
public linkedList()
{
start=null;
size = 0;
}
Function to check if list is empty
public boolean isEmpty()
{
return start == null;
}
Function to check size of list
public int getSize()
{
return size;
}
Function to insert an element
public void insert(int val)
{
Node nptr, ptr, tmp = null;
nptr = new Node(val, null);
boolean ins = false;
if (start == null)
start = nptr;
else if (val <= start.getData())
{
nptr.setLink(start);
start = nptr;
}
else
{
tmp = start;
ptr = start.getLink();
while(ptr != null)
{
if (val >= tmp.getData() && val <= ptr.getData())
{
tmp.setLink(nptr);
nptr.setLink(ptr);
ins = true;
break;
}
else
{
tmp = ptr;
ptr = ptr.getLink();
}
}
if (ins == false)
{
tmp.setLink(nptr);
}
}
size++;
}
Function to display elements
public void display()
{
System.out.print("Sorted Singly Linked List = ");
if (size == 0)
{
System.out.print("empty ");
return;
}
if (start.getLink() == null)
{
System.out.println(start.getData() );
return;
}
Node ptr = start;
System.out.print(start.getData()+ "->");
ptr = start.getLink();
while (ptr.getLink() != null) {
System.out.print(ptr.getData()+ "->");
ptr = ptr.getLink();
}
System.out.print(ptr.getData()+ " ");
}
}
import java.text.DecimalFormat;
import java.util.Arrays;
public class Student implements LinkedList{
private String Firstname;
private String Lastname;
private int GPA;
private int UIA;
private int NetID;
private int Age;
private Char Gender;
// The constructor
// initializes the instance variables
public Student (String firstname,String Lastname, int NetID, int UIA,int GPA,int Age,Char Gende){
firstname = this.getfirstName();
lastname = this.getlastName();
id = this.getId();
//System.out.println(firstname+" "+lastname+" "+GPA+" "+UIA+" "+NetID+" "+Age+" "+Gender+" "+" "+);
}
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getMajor() {
return major;
}
public double getGpa() {
return gpa;
}
public String getUin() {
return uin;
}
public String getNetID() {
return netID;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setMajor(String major) {
this.major = major;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public void setUin(String uin) {
this.uin = uin;
}
public void setNetID(String netID) {
this.netID = netID;
}
public void setAge(int age) {
this.age = age;
}
public void setGender(String gender) {
this.gender = gender;
}
public class StudentLinkedList implements LinkedList{
public String toString(){
String res = "Course: " + course + " ";
for(StudentLLNode curr = head; curr !=null; curr=curr.getNext()){
StudentIF nS = curr.getStd();
res = res + nS + " ";
}
return res;
}
public boolean insert(Linked List l) {
StudentLinkedListNode current = head;
if (l == null) {
return false;
}
if (head == null) {
StudentLinkedListNode student = new StudentLLNode(l);
head = student;
size++;
return true;
} else {
if (curr.getStd().compareTo(l) == 0) {
//System.out.println("working");
return false;
}
while (curr.getNext() != null) {
if(s.compareTo(curr.getStd()) == 1){
//c
}
curr = curr.getNext();
}
StudentLinkedListNode student1 = new StudentLinkedListNode(s);
curr.setNext(student);
size++;
return true;
}
}
public class SortedSinglyLinkedList
{
public static void main(String[] args)
{
// Display List
l.display();
System.out.println(" firstname+" "+lastname+" "+GPA+" "+UIA+" "+NetID+" "+Age+" "+Gender+" "+" "+);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.