package chapter20230901.member.linkedlist;
import java.util.*;
import chapter20230901.member.Member;
public class MemberLinkedList {
private final LinkedList<Member> linkedList;
public MemberLinkedList() {
this.linkedList = new LinkedList<>();
}
public void addMember(Member member) {
linkedList.add(member);
}
public boolean removeMember(int memberID) {
for(Member member : linkedList) {
if(member.getMemberID() == memberID) {
linkedList.remove(member);
return true;
}
}
System.out.println(memberID + " 가 존재하지 않습니다.");
return false;
}
public void showAllMember() {
for (Member member : linkedList) {
System.out.println(member);
}
System.out.println();
}
}
package chapter20230901.member.linkedlist;
import chapter20230901.member.Member;
public class MemberLinkedListTest {
public static void main(String[] args) {
MemberLinkedList memberArrayList = new MemberLinkedList();
Member memberLee = new Member(1001, "이지원");
Member memberSon = new Member(1002, "손민국");
Member memberPark = new Member(1003, "박서원");
Member memberHong = new Member(1004, "홍길동");
memberArrayList.addMember(memberLee);
memberArrayList.addMember(memberSon);
memberArrayList.addMember(memberPark);
memberArrayList.addMember(memberHong);
memberArrayList.showAllMember();
memberArrayList.removeMember(1004);
memberArrayList.showAllMember();
}
}
package chapter20230901.member;
public class Member {
private int memberID;
private String memberName;
public Member(int memberID, String memberName) {
super();
this.memberID = memberID;
this.memberName = memberName;
}
public int getMemberID() {
return memberID;
}
public void setMemberID(int memberID) {
this.memberID = memberID;
}
public String getMemberName() {
return memberName;
}
public void setMemberName(String memberName) {
this.memberName = memberName;
}
@Override
public String toString() {
return memberName + "회원님의 아이디는 " + memberID + " 입니다.";
}
}