Answer to Question #172648 in Java | JSP | JSF for Sawaira

Question #172648

Implement a code for Students information using linked list Such as student name Registration no and cgpa Write client code to retain data of students who have greater than 1.3 cgpa and also delete the record of students whose less than 1.3 CGPA java code


1
Expert's answer
2021-03-17T20:18:48-0400
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 void filter() {
        if (head != null) {
            Node cur = head;
            while (cur != null) {
                if (cur.getData().getCgpa() < 1.3) {
                    head = cur.getNext();
                    if (head == null) {
                        tail = null;
                    }
                } else if (cur.getNext() != null) {
                    if (cur.getNext().getData().getCgpa() < 1.3) {
                        if (cur.getNext().getNext() == null) {
                            tail = cur;
                            cur.setNext(null);
                        } else {
                            cur.setNext(cur.getNext().getNext());
                        }
                    }
                }
                cur = cur.getNext();
            }
        }
    }

}


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

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

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!

Comments

Assignment Expert
18.03.21, 07:40

Dear Sawaira, You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!

Sawaira
18.03.21, 07:38

Thank you so much

Leave a comment

LATEST TUTORIALS
New on Blog