Question
import java.util.Scanner; public class student { private String name; public int age; private int sid; private String add; private String gender; private student ptr; public
import java.util.Scanner;
public class student {
private String name; public int age; private int sid; private String add; private String gender; private student ptr; public student head, mover, newnode; //Create an node of student class student prvs; student nextnode;
student() // Create a Constucrt of student class { head = null;//head is a start of link list }
student(String name, int age, int sid, String add, String gender, student head) //Create a Constructor of student class { this.name = name; this.age = age;
this.sid = sid;
this.add = add;
this.gender = gender; this.head = head; }
student(int i) //Create an other Constructor of student class {
mover = head; while (mover.ptr != null) { mover = mover.ptr; } mover.ptr = mover.ptr.ptr;
}
public void Addstudent(int n, String name, int age, String add, String gender) {//Add required information of addstudent function
newnode = new student(); //Create new object of student class newnode.sid = n; newnode.name = name; newnode.age = age; newnode.gender = gender; newnode.add = add; if (head == null) { //head is a start of the Link list // If link list empty head = newnode; newnode.ptr = null; } else // If link list is not empty { mover = head; while (mover != null && (mover.sid) < n)// check postition to add student information { prvs = mover; mover = mover.ptr; } if (prvs == null) { head = newnode; newnode.ptr = mover; } else { prvs.ptr = newnode; newnode.ptr = mover; } }
}
public void Printstudent() { mover = head; while (mover != null) {
System.out.println("Name:" + " " + mover.name);//Print all student name add in addstudent function mover = mover.ptr;
}
}
public void Removestudent(int s) { //Pass local variable in remove function
if(head == null) return; if (head.sid == s) //if 1st node or head { head = head.ptr;
} else // if remove student in middle { mover = head; while (mover != null && mover.sid != s) { prvs = mover; mover = mover.ptr; } //Enter not found student ID in student class if (mover == null && prvs.sid != s) { System.out.println("student id not found");//No match student ID } else { prvs.ptr = mover.ptr;
} } }
void updatestudent(int nn) { //Pass local variable in update function String name; // New variable of student class use for update student new information` String address; mover = head; while (mover != null && mover.sid != nn) { //Check positio of student prvs = mover; mover = mover.ptr; } if (mover == null && prvs.sid != nn) { //No position match of student ID System.out.println("student id not found"); } else { System.out.println("Student Inoformation: "); System.out.println("Name: " + mover.name + ", Age: " + mover.age + ", Address: " + mover.add + ", Gender: " + mover.gender); System.out.println("Enter Updated Address: "); Scanner input = new Scanner(System.in); address = input.nextLine(); //Enter new address of student to update System.out.println("Enter New Name for student:"); name = input.nextLine(); //Enter new name of student to update mover.name = name; mover.add = address; } } }
PLEASE EXPLAIN WHAT CODE IS DOING LINE by LINE
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