티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | package oop; /** * 요구사항 (기능정의) * <사용자기능> * 1. 회원가입 * 2. 로그인 * 3. 비번 수정 * 4. 회원탈퇴 * 5. 아이디 존재 체크 * 6. 마이페이지 * ********** * <관리자기능> * 7. 회원목록 * 8. 아이디검색 * 9. 이름검색 * 10. 전체 회원수 */ import java.util.Scanner; class Member { private String userid,password, name; public Member() { // TODO Auto-generated constructor stub } public void setUserid(String userid) { this.userid = userid; } public String getUserid() { return this.userid; } public void setPassword(String password) { this.password = password; } public String getPassword() { return this.password; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public String toString() { return "[아이디: "+userid+", 비번: "+password+", 이름: "+name+"]"; } } interface MemberService { // 1. 회원가입 public void join(Member member); // 2. 로그인 public String login(Member member); // 3. 회원목록 public Member[] list(); // 4. 아이디 중복체크 public String existId(String id); // 5. 비번 수정 public String changePassword(Member member); // 6. 회원탈퇴 public String withdrawal (Member member); // 7. 아이디검색 public Member idSearch(String id); // 8. 이름 검색 public Member[] nameSearch(String name); // 9. 전체 회원수 public int count(); } class MemberServiceImpl implements MemberService{ private Member[] members; private int count; public MemberServiceImpl() { members = new Member[3]; count = 0; } // 1. 회원가입 @Override public void join(Member member) { members[count] = member; count++; } // 2. 로그인 @Override public String login(Member member) { String result = "FAIL"; for(int i=0;i< count; i++) { if(member.getUserid().equals(members[i].getUserid()) && member.getPassword().equals(members[i].getPassword())) { result = "SUCCESS"; break; } } return result; } // 3. 회원목록 @Override public Member[] list() { return members; } // 4. 아이디 중복체크 @Override public String existId(String id) { String result = "중복없음"; for(int i=0; i< count; i++) { if(id.equals(members[i].getUserid())) { result ="중복된 아이디"; } } return result; } // 5. 비번 수정 @Override public String changePassword(Member member) { String result = "수정실패"; for(int i =0; i< count; i++) { if(member.getUserid().equals(members[i].getUserid())) { members[i].setPassword(member.getPassword()); result = "수정성공"; break; } } return result; } // 6. 회원탈퇴 @Override public String withdrawal(Member member) { String result = "탈퇴 실패"; for(int i=0; i< count; i++) { if(member.getUserid().equals(members[i].getUserid()) && member.getPassword().equals(members[i].getPassword())) { members[i] = members[count-1]; members[count-1] = null; count --; result = "탈퇴 성공"; break; } } return result; } // 7. 아이디검색 @Override public Member idSearch(String id) { Member member = new Member(); for(int i =0; i< members.length; i++) { if(id.equals(members[i].getUserid())) { member = members[i]; break; } } return member; } // 8. 이름 검색(동명이인 처리필요) @Override public Member[] nameSearch(String name) { int cnt = 0; // 동명이인의 수 for(int i =0; i< members.length; i++) { if(name.equals(members[i].getName())) { cnt++; } } Member[] searchMembers = new Member[cnt]; int k = 0; for(int i =0; i< members.length; i++) { if(name.equals(members[i].getName())) { searchMembers[k] = members[i]; k++; if(k == cnt) break; } } return searchMembers; } // 9. 전체 회원수 @Override public int count() { return count; } } public class MemberApp { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Member member = null; MemberService memberService = new MemberServiceImpl(); while (true) { System.out.println("메뉴: 0.종료 1.회원가입 2.로그인" + "5.아이디존재 7.회원목록"); switch (scanner.nextInt()) { case 0: System.out.println("종료");return; case 1: // 1. 회원가입 member = new Member(); System.out.println("회원가입"); System.out.println("아이디: "); member.setUserid(scanner.next()); System.out.println("비밀번호: "); member.setPassword(scanner.next()); System.out.println("이름: "); member.setName(scanner.next()); memberService.join(member); break; case 2: // 2. 로그인 System.out.println("로그인"); member = new Member(); System.out.println("아이디: "); member.setUserid(scanner.next()); System.out.println("비밀번호: "); member.setPassword(scanner.next()); String result= memberService.login(member); System.out.println(result); break; case 3: // 3. 회원목록 System.out.println("목록보기"); Member[] list= memberService.list(); for(int i=0;i < 3;i++) { System.out.println(list[i].toString()); } break; case 4: // 4. 아이디 중복체크 System.out.println("아이디 체크"); member = new Member(); System.out.println("아이디: "); result= memberService.existId(scanner.next()); System.out.println(result); break; case 5: // 5. 비번 수정 System.out.println("비번 수정"); member = new Member(); System.out.println("아이디: "); member.setUserid(scanner.next()); System.out.println("변경할 비번: "); member.setPassword(scanner.next()); result= memberService.changePassword(member); System.out.println(result); break; case 6: // 6. 회원탈퇴 System.out.println("회원탈퇴"); member = new Member(); System.out.println("삭제할 아이디: "); member.setUserid(scanner.next()); System.out.println("비번 다시 입력: "); member.setPassword(scanner.next()); result= memberService.withdrawal(member); System.out.println(result); break; case 7: // 7. 아이디검색 System.out.println("아이디검색"); member = new Member(); member = memberService.idSearch(scanner.next()); System.out.println(member.toString()); break; case 8: // 8. 이름 검색 Member[] findedMembers = memberService.nameSearch(scanner.next()); for(Member m: findedMembers) { System.out.println(m.toString()); } break; case 9: // 9. 전체 회원수 System.out.println(memberService.count()); break; default: System.out.println("메뉴에 없는 기능입니다."); break; } } } } | cs |
'1. 자바' 카테고리의 다른 글
OOP - Phone.java (0) | 2020.08.14 |
---|---|
CRUD - Person.java (0) | 2020.08.14 |
행렬(Matrix) - Lotto.java (0) | 2020.08.14 |
OOP - ProductCart.java (0) | 2020.08.14 |
스프링/--/하이파/ 타이타닉 PassengerRepository.java (0) | 2020.08.07 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- maven
- nodejs
- mariadb
- tensorflow
- ERD
- SQLAlchemy
- AWS
- JPA
- Python
- Git
- intellij
- COLAB
- JUnit
- vscode
- FLASK
- springMVC
- Django
- Mlearn
- Eclipse
- jQuery
- Algorithm
- Mongo
- KAFKA
- Oracle
- Java
- database
- terms
- React
- SpringBoot
- docker
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함