티스토리 뷰
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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | package oop; import java.util.Scanner; /* * RFP * Person(id, pass, name:String) * - Student(ssn:String, score:int), * - Admin(rank:int) * <사용자기능> Student * 1. 회원가입 * 2. 로그인 * 3. 비번 수정 * 4. 회원탈퇴 * 5. 아이디 존재 체크 * 6. 마이페이지 * 7. 점수 입력 * ********** * <관리자기능> Admin * 1. 회원목록 * 2. 아이디검색 * 3. 이름검색 * 4. 전체 회원수 * 5. 성적별 현황 (스코어 기준 이름 내림차순 예.. 1등 이순신(여) 98점, 2등 김유신(남) 85점... ) */ class Constants{ public static final String MAN_MENU = "0.시스템종료 1.학생 2.관리자"; public static final String STUDENT_MENU = "\n0.학생화면 종료 \n"+ " 1. 회원가입\n" + " 2. 로그인 \n" + " 3. 비번 수정\n" + " 4. 회원탈퇴\n" + " 5. 아이디 존재 체크\n" + " 6. 마이페이지\n" + " 7. 점수 입력\n"; public static final String ADMIN_MENU = "\n0.관리자화면 종료\n "+ "1. 회원목록\n" + "2. 아이디검색\n" + "3. 이름검색\n" + "4. 전체 회원수\n" + "5. 성적별 현황\n"; public static final String PERSON_SPEC = "아이디: %s 비번: %s 이름: %s"; public static final String STUDENT_SPEC = "아이디: %s 비번: %s 이름: %s(%s) 주민번호: %s 점수: %d"; public static final String ADMIN_SPEC = "관리자 아이디: %s 비번: %s 이름: %s 등급: %d"; } class Person{ protected String id, pass, name; public String getId() {return id;} public void setId(String id) {this.id = id;} public String getPass() {return pass;} public void setPass(String pass) {this.pass = pass;} public String getName() {return name;} public void setName(String name) {this.name = name;} @Override public String toString() { return String.format(Constants.PERSON_SPEC, id, pass, name); } } class Student extends Person{ private String ssn, gender;private int score; public String getSsn() {return ssn;} public void setSsn(String ssn) {this.ssn = ssn;} public int getScore() {return score;} public void setScore(int score) {this.score = score;} public String getGender() {return gender;} public void setGender(String gender) {this.gender = gender;} @Override public String toString() { return String.format(Constants.STUDENT_SPEC, id, pass, name, gender, ssn, score); } } class Admin extends Person{ private int rank; public int getRank() {return rank;} public void setRank(int rank) {this.rank = rank;} @Override public String toString() { return String.format(Constants.ADMIN_SPEC, id, pass, name, rank); } } interface PersonService{ /** 1. 회원가입 */ public void join(Student student); /** 2. 로그인 */ public String login(Student student); /** 3. 비번 수정 */ public void changePass(Student student); /** 4. 회원탈퇴 */ public void remove(Student student); /** 5. 아이디 존재 체크 */ public String existId(String id); /** 6. 마이페이지 */ public Student mypage(String id); /** 7. 점수 입력 */ public void score(int[] arr); /** 8. 회원목록 */ public Student[] studentList(); /** 9. 아이디검색 */ public Student idSearch(String id); /** 10. 이름검색 */ public Student[] nameSearch(String name); /** 11. 전체 회원수 */ public int studentCount(); /** 12. 성적별 현황 */ public Student[] gradeRank(); } class PersonServiceImpl implements PersonService { private Student[] students; private int count; public PersonServiceImpl() { students = new Student[4]; count = 0; } @Override public void join(Student student) { /** 1. 회원가입 */ String gender = student.getSsn(); String result = ""; switch(gender.charAt(7)) { // 900505-1 이면 1의 인덱스는 7 case '1': case '3': result = "남"; break; case '2': case '4': result = "여"; break; default : result ="오류"; } student.setGender(result); students[count] = student; count++; } @Override public String login(Student student) { /** 2. 로그인 */ String result = "로그인 실패"; for(int i= 0; i < count; i++) { if(student.getId().equals(students[i].getId()) && student.getPass().equals(students[i].getPass())) { result = "로그인 성공"; break; } } return result; } @Override public void changePass(Student student) { /** 3. 비번 수정 */ for(int i= 0; i < count; i++) { if(student.getId().equals(students[i].getId())) { students[i].setPass(student.getPass()); break; } } } @Override public void remove(Student student) { /** 4. 회원탈퇴 */ for(int i= 0; i < count; i++) { if(student.getId().equals(students[i].getId()) && student.getPass().equals(students[i].getPass())) { students[i] = students[count - 1]; students[count - 1]= null; count --; break; } } } @Override public String existId(String id) { /** 5. 아이디 존재 체크 */ String result = "사용 가능한 아이디"; for(int i= 0; i < count; i++) { if(id.equals(students[i].getId())) { result ="이미 존재하는 아이디"; break; } } return result; } @Override public Student mypage(String id) { /** 6. 마이페이지 */ Student student = new Student(); for(int i= 0; i < count; i++) { if(id.equals(students[i].getId())) { student = students[i]; break; } } return student; } @Override public void score(int[] arr) { /** 7. 점수 입력 */ for(int i=0; i< count; i++) { students[i].setScore(arr[i]); } } @Override public Student[] studentList() { /** 8. 회원목록 */ return students; } @Override public Student idSearch(String id) { Student student = new Student(); /** 9. 아이디검색 */ for(int i= 0; i < count; i++) { if(id.equals(students[i].getId())) { student = students[i]; break; } } return student; } @Override public Student[] nameSearch(String name) { /** 10. 이름검색 */ int cnt = 0; for(int i= 0; i < count; i++) { if(name.equals(students[i].getName())) { cnt++; } } Student[] sameNames = new Student[cnt]; int k =0; for(int i= 0; i < count; i++) { if(name.equals(students[i].getName())) { sameNames[k] = students[i]; k++; if(cnt == k) break; } } return sameNames; } @Override public int studentCount() { /** 11. 전체 회원수 */ return count; } @Override public Student[] gradeRank() { /** 12. 성적별 현황 */ for(int i=0; i< count; i++) { for(int j= 0; j < i; j++) { if(students[i].getScore() > students[j].getScore()) { Student t = students[i]; students[i] = students[j]; students[j] = t; } } } return students; } } public class PersonApp { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); PersonService service = new PersonServiceImpl(); Student student = null; Admin admin = null; while(true) { System.out.println(Constants.MAN_MENU); switch(scanner.nextInt()) { case 0: return; case 1: student(scanner, student, service); break; case 2: admin(scanner, admin, service); break; default: System.out.println("1. 학생 2. 관리자 선택바랍니다.");break; } } } public static void student(Scanner scanner, Student student, PersonService service) { System.out.println(Constants.STUDENT_MENU); // scanner 입력 생략 String[] id = {"kim","you","lee","lee"}; String[] name = {"김유신","유관순","이순신","이순신"}; String[] ssn = {"900101-1","900501-2","900801-1","901201-2"}; String result =""; switch (scanner.nextInt()) { case 0:return; case 1: /** 1. 회원가입 */ for(int i=0; i < id.length; i ++) { student = new Student(); student.setId(id[i]); student.setPass("1"); student.setName(name[i]); student.setSsn(ssn[i]); service.join(student); } break; case 2: /** 2. 로그인 */ student = new Student(); student.setId(id[0]); student.setPass("1"); result = service.login(student); System.out.println(result); break; case 3: /** 3. 비번 수정 */ student = new Student(); student.setId(id[2]); student.setPass("2"); service.changePass(student); break; case 4: /** 4. 회원탈퇴 */ student.setId(id[0]); student.setPass("1"); service.remove(student); break; case 5: /** 5. 아이디 존재 체크 */ System.out.println(service.existId("kim")); break; case 6: /** 6. 마이페이지 */ System.out.println(service.mypage("kim")); break; case 7: /** 7. 점수 입력 */ int[] scores = {70, 60, 80, 30}; service.score(scores); break; default: break; } } public static void admin(Scanner scanner, Admin admin, PersonService service) { System.out.println(Constants.ADMIN_MENU); switch (scanner.nextInt()) { case 0:return; case 1: Student[] list = service.studentList(); for(Student s : list) { System.out.println(s.toString()); } break; case 2: System.out.println(service.idSearch("kim").toString()); break; case 3: Student[] sameNames = service.nameSearch("이순신"); for(Student s : sameNames) { System.out.println(s.toString()); } break; case 4: System.out.printf("총 %d 명",service.studentCount()); break; case 5: Student[] ranks = service.gradeRank(); for(Student s : ranks) { System.out.println(s.toString()); } break; default: break; } } } | cs |
'1. 자바' 카테고리의 다른 글
Array - Player.java (0) | 2020.08.14 |
---|---|
OOP - Phone.java (0) | 2020.08.14 |
CRUD - Member.java (0) | 2020.08.14 |
행렬(Matrix) - Lotto.java (0) | 2020.08.14 |
OOP - ProductCart.java (0) | 2020.08.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- ERD
- springMVC
- maven
- intellij
- terms
- JUnit
- docker
- KAFKA
- AWS
- Eclipse
- SpringBoot
- Git
- mariadb
- Algorithm
- Python
- Java
- React
- JPA
- FLASK
- tensorflow
- COLAB
- Mongo
- vscode
- Oracle
- Django
- nodejs
- SQLAlchemy
- Mlearn
- database
- jQuery
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함