Question #172329

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


Expert's answer

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;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS