السلام عليكم
ممكن المساعدة في هذا البرنامج فى الأتي
كيف يمكنني تجنب طباعة نفس (ID) للطالب وأين يمكنني كتابة هذا الكود ومشكورين .
package Linkedlist2;
public class Node {
Student stu;
Node next;
public Node(Student s){
stu=s;
}
}package Linkedlist2;
public class Student {
private int st_Id;
private String firstName;
private String lastName;
public Student(int id, String fn, String ln) {
st_Id = id;
firstName = fn;
lastName = ln;
}
public void Setst_Id(int id) {
st_Id = id;
}
public void SetfirstName(String fn) {
firstName = fn;
}
public void SetlastName(String ln) {
lastName = ln;
}
public int getst_Id() {
return st_Id;
}
public String getfirstName() {
return firstName;
}
public String getlastName() {
return lastName;
}
}package Linkedlist2;
public class StudentLinkedList {
Node first;
public StudentLinkedList() {
first = null;
}
public void insertfirst(Node n) {
n.next = first;
first = n;
}
public void printlist() {
Node current = first;
while (current != null) {
System.out.println("the student ID is : " + current.stu.getst_Id());
System.out.println("the Student first name is : " + current.stu.getfirstName());
System.out.println("the Student last name is : " + current.stu.getlastName());
System.out.println("===============================================");
current = current.next;
}
}
}
package Linkedlist2;
public class StudentLinkedListTest {
public static void main(String[] args) {
StudentLinkedList list1 = new StudentLinkedList();
Student s1 = new Student(115001, "mohammed", "nasyia");
Node n = new Node(s1);
list1.insertfirst(n);
s1 = new Student(115001, "ali", "alhamdi");
n = new Node(s1);
list1.insertfirst(n);
list1.printlist();
}
}