How to Implement a Linked List class to store the following information about students:
Registration number of the student
Name of the student
CGPA of the student
public class Student {
private int registrationNumber;
private String name;
private double cgpa;
public Student(int registrationNumber, String name, double cgpa) {
this.registrationNumber = registrationNumber;
this.name = name;
this.cgpa = cgpa;
}
public int getRegistrationNumber() {
return registrationNumber;
}
public String getName() {
return name;
}
public double getCgpa() {
return cgpa;
}
public void setRegistrationNumber(int registrationNumber) {
this.registrationNumber = registrationNumber;
}
public void setName(String name) {
this.name = name;
}
public void setCgpa(double cgpa) {
this.cgpa = cgpa;
}
}
public class LinkedList {
private Node head;
private Node tail;
public boolean add(Student student) {
Node node = new Node(student);
if (head == null) {
head = node;
} else {
tail.setNext(node);
}
tail = node;
return true;
}
}
public class Node {
private Node next;
private Student data;
public Node(Student data) {
this.data = data;
}
public Student getData() {
return data;
}
public void setData(Student data) {
this.data = data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
Comments
Dear Sawaira, post a new question please
Write client code, such that based on the registration number of the students, Retain only the record of the students whose GPA is greater than 1.3 and remove all the students record whose GPA is less than 1.3 previous program part 2
Leave a comment