Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        250x250
    
    
  | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
                            Tags
                            
                        
                          
                          - pandas
- javascript
- HTML
- 판다스
- JQuery
- Python
- 파이썬
- 제이쿼리
- MLB
- gcp
- 기록
- 배포
- CSS
- Spring
- 앱
- mlb stats api
- 오라클
- java
- 안드로이드
- 어플
- 자바
- oracle
- kotlin
- 코틀린
- 시간
- streamlit
- 자바스크립트
- 스프링
- 프로젝트
- Android
                            Archives
                            
                        
                          
                          - Today
- Total
develope_kkyu
[JAVA] 은행 계좌 만들기(비밀번호 추가) 본문
728x90
    
    
  Accoung.java
public class Account {
	private String ano;
	private String owner;
	private int balance;
	private int password;
	
	public Account(String ano, String owner, int balance, int password) {
		this.ano = ano;
		this.owner = owner;
		this.balance = balance;
		this.password = password;
		}
	
	public String getAno() {
		return ano;			// this.ano
		}
	public void setAno(String ano) {
		this.ano = ano;
	}
	public String getOwner() {
		return owner;		// this.owner
	}
	public void setOwner(String owner) { 
		this.owner = owner;
	}
	public int getBalance() {
		return balance;		// this.balance
	}
	public void setBalance(int balance) {
		this.balance = balance;
	}
	public int getPassword() {
		return password;		
	}
	public void setPassword(int password) {
		this.password = password;
	}
}BankApplication.java
import java.util.Scanner;
public class BankApplication {
	private static Account[] accountArray = new Account[100];
	private static Scanner sc= new Scanner(System.in);
	public static void main(String[] args) {
		boolean run = true;
		while(run) {
			System.out.println("------------------------------------------");
			System.out.println("1.계좌생성 | 2.계좌목록 | 3.예금 | 4.출금 | 5.종료");
			System.out.println("------------------------------------------");
			System.out.print("선택 > ");
			int selectNo = sc.nextInt();
			
			if(selectNo == 1) {
				createAccount();
			} else if(selectNo == 2) {
				accountList();
			}else if(selectNo == 3) {
				deposit();
			}else if(selectNo == 4) {
				withdraw();
			}else if(selectNo == 5) {
				run = false;
			}
		}
		System.out.println("프로그램 종료");
	}
	private static void createAccount() {
		System.out.println("--------------");
		System.out.println("계좌생성");
		System.out.println("--------------");
		System.out.print("계좌번호: ");
		String ano = sc.next();
		System.out.print("계좌주: ");
		String owner = sc.next();
		System.out.print("초기입금액: ");
		int balance = sc.nextInt();
		System.out.print("비밀번호: ");
		int password = sc.nextInt();
		
		int a = 0;
		
		Account ac = new Account(ano, owner, balance, password);
		
		for(a=0; a<accountArray.length; a++) {
			if(accountArray[a] == null) {
				accountArray[a] = ac;
				break;
			}
		}
		System.out.println("결과:계좌가 생성되었습니다.");
	}
	private static void accountList() {
		System.out.println("--------------");
		System.out.println("계좌목록");
		System.out.println("--------------");
		for(int a=0; a<accountArray.length; a++) {
			if(accountArray[a] == null) {
				break;
			}
		System.out.printf("%s\t%s\t%d\n", accountArray[a].getAno(), accountArray[a].getOwner(), accountArray[a].getBalance());
		}
	}
	private static void deposit() {
		System.out.println("-------");
		System.out.println("예금");
		System.out.println("-------");
		System.out.print("계좌번호: ");
		String ano = sc.next();
		System.out.print("비밀번호: ");
		int password = sc.nextInt();
		Account ac = findAccount(ano, password);
		System.out.print("예금액: ");
		int deposit = sc.nextInt();
		int currentBalance = ac.getBalance();
		int nextBalance = currentBalance + deposit;
		ac.setBalance(nextBalance);
		System.out.println("예금이 성공되었습니다.");
		
		
		
	}
	private static void withdraw(){
		System.out.println("-------");
		System.out.println("출금");
		System.out.println("-------");
		System.out.print("계좌번호: ");
		String ano = sc.next();
		System.out.print("비밀번호: ");
		Account ac = findAccount(ano, password);
		System.out.print("출금액: ");
		int withdraw = sc.nextInt();
		int currentBalance = ac.getBalance();
		int nextBalance = currentBalance - withdraw;
		ac.setBalance(nextBalance);
		System.out.println("출금이 성공되었습니다.");
	}
	private static Account findAccount(String ano, int password) {
		int a = 0;
				for(a=0; a<accountArray.length; a++) {
					if(ano.equals(accountArrbay[a].getAno()) && password.equals(accountArray[a].getPassword())) {
						break;
					}
				}
				return accountArray[a];
	}
}
728x90
    
    
  'JAVA > Java SE' 카테고리의 다른 글
| [JAVA] 남은 시간 계산 (1) | 2022.12.21 | 
|---|---|
| [JAVA] 현재 시간 (0) | 2022.12.21 | 
| [JAVA] 은행 계좌 만들기 (0) | 2022.12.21 | 
| [JAVA] 두 개의 주사위 눈의 합 (0) | 2022.12.21 | 
| [JAVA] 1부터 100까지 더하기 (0) | 2022.12.21 | 
