공백._. 2022. 7. 14. 11:14
(1) FOR구문으로 9(종료기능)이 나올 때까지 반복_무한반복FOR(;;)
(2) int ID, int PW 입력받고, 조회/입금/출금 파트에서 확인.
package miniproject; 
import java.util.Scanner; 
public class Bank_3 { 
	public static void main(String[] args) { 
		// 변수 
		int num = 0, id = 0, pass = 0; 
		int subid=0, subpw=0; 
		double balance = 0, plus = 0; 
		Scanner scanner = new Scanner(System.in); 
		for (;;) { 
			System.out.println("======BANK======"); 
			System.out.println("1. 추가"); 
			System.out.println("2. 조회"); 
			System.out.println("3. 입금"); 
			System.out.println("4. 출금"); 
			System.out.println("5. 삭제"); 
			System.out.println("9. 종료"); 
			// 입력 
			System.out.print("입력>>>"); 
			num = scanner.nextInt(); 
			// 처리, 출력 
			if (num == 1) { 
				System.out.print("ㅁ 추가기능입니다. \r\n"); 
				System.out.print("본인확인ID: "); 
				id = scanner.nextInt(); 
				System.out.print("본인확인pass: "); 
				pass = scanner.nextInt(); 
				System.out.print("본인확인BALANCE: "); 
				balance = scanner.nextDouble(); 
				System.out.println("ㅁ 아이디 :" + id); 
				System.out.println("ㅁ 비밀번호 :" + pass); 
				System.out.println("ㅁ 잔	액 :" + balance); 
				System.out.println("설정되어 있습니다."); 
			} // end if1 
			if (num == 2) { 
				System.out.println("ㅁ 조회기능입니다."); 
				System.out.print("본인확인ID : "); 
				subid = scanner.nextInt(); 
				System.out.print("본인확인pass : "); 
				subpw = scanner.nextInt(); 
				if (id == subid && pass == subpw) { 
					System.out.println("==반갑습니다 고객님" + "\r\n" + "ID :" + id + "\r\n" + "pass : " + pass + "\r\n" 
							+ "balance : " + balance + "\r\n"); 
				} else { 
					System.out.println("다시 확인해주세요." + "\r\n"); 
				} 
			} // end if2 
			if (num == 3) { 
				System.out.println("ㅁ 입금기능입니다."); 
				System.out.print("본인확인 ID : "); 
				id = scanner.nextInt(); 
				System.out.print("본인확인pass : "); 
				pass = scanner.nextInt(); 
				if (id == subpw && pass == subpw) { 
					System.out.print("입금할 금액을 입력해주세요>"); 
					plus = scanner.nextInt(); 
					if (plus < 0) { 
						System.out.println("금액이 모자랍니다." + "/r/n" + "종료합니다." + "\r\n"); 
					} else { 
						System.out.println("==잔액확인" + "\r\n" + "ID :" + id + "\r\n" + "pass :" + pass + "\r\n" 
								+ "balance : " + (balance + plus) + "\r\n"); 
					} 
					; 
				} else { 
					System.out.println("다시 확인해주세요."); 
				} 
			} // end if3 
			if (num == 4) { 
				System.out.println("ㅁ 출금기능입니다."); 
				System.out.print("본인확인 ID : "); 
				id = scanner.nextInt(); 
				System.out.print("본인확인 pass : "); 
				pass = scanner.nextInt(); 
				if (id == subid && pass == subpw) { 
					System.out.print("출금할 금액을 입력해주세요>"); 
					plus = scanner.nextInt(); 
					if (plus >= balance) { 
						System.out.print("금액이 모자랍니다." + "\r\n" + "종료합니다." + "\r\n"); 
					} else { 
						System.out.println("==잔액확인" + "\r\n" + "ID : 1" + "\r\n" + "pass : 1" + "\r\n" + "balance : " 
								+ (balance - plus) + "\r\n"); 
					} 
					; 
				} else { 
					System.out.println("다시 확인해주세요."); 
				} 
			} // end if4 
			if (num == 5) { 
				System.out.println("ㅁ 삭제기능입니다." + "\r\n" + "== 잔액확인" + "\r\n" + "ID : 0" + "\r\n" + "pass : 0" + "\r\n" 
						+ "balance : 0.0" + "\r\n"); 
			} // end if5 
			if (num == 9) { 
				System.out.println("ㅁ 종료기능입니다."); 
				break; 
			} 
		} // end for 
	}// end main 
}// end class