-
숙련 과제를 진행하다가 업무 분할로 인해 진행에 어려움이 생겨 임시로 UserEntity 만들어서
값 넣고 잘 돌아가나 확인 해보고 이리저리 치이다가 후발대 수업듣고 진정이됬네요 ㅋㅋ
객체지향적으로 프로그래밍 하기 시작했는데 간단한 카드 발급 및 결제 하는 내용인데
if 로 다 섞어 내자니 잔액부족과 비밀번호 오류를 동시에 체크하지 못해서 고민하다가
아래와 같이 switch 문을 통해 해결 했습니다. 오늘 jwt 강의 본다고 진도를 많이 못나가서 걱정입니다..
Card[] c = new Card[2]; for (int i = 0; i < 2; i++) { System.out.println("이름: "); name = sc.nextLine(); System.out.println("비밀번호: "); password = sc.nextInt(); System.out.println("잔액: "); belance = sc.nextInt(); sc.nextLine(); c[i] = new Card(name, password, belance); } for (int i = 0; i < 2; i++) { System.out.println(c[i].user + " 결재중 "); System.out.println("비밀번호 입력: "); checkPw = sc.nextInt(); if (checkPw == c[i].getPassword()) { checkNum = 1; System.out.println("비밀번호가 확인되었습니다"); switch (checkNum) { case 1: if (c[i].getBalance() > 5000) { System.out.println("카드에서 5000원 차감되었습니다"); c[i].balance -= 5000; System.out.println(c[i].balance); break; } else { System.out.println("잔액 부족"); } } } else { System.out.println(" 비밀번호 불일치"); } }