직업은 선물 트레이더

[과제]JAVA. 은행 계좌관리 소프트웨어

잊어버린 과거

네이밍은 참 재밌다. 금융권 계좌관리라고 지을려다가 그냥 은행으로 하는걸로.. 사실 소프트웨어 글자만 붙어도 왠지 굉장히 전문적으로 보인다. 이런것이 바로 과대광고의 시작인가..

 

 

은행 계좌관리 시뮬레이션 소프트웨어

 

 

 

컴퓨터공학과 2010151035 장용하.


 


<class Bank>


import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.*;



public class Bank {

        public static void main(String[] args) {

                

                Account ac[] = new Account[6];

                

                ac[0] = new Account("000-999-2", "연어회", 1000);

                ac[1] = new Account("00-9912-35", "참치회", 2000);

                

                ac[2] = new CAccount("596-99-5", "광어회", 3000, "1-990");

                ac[3] = new CAccount("891-145-1", "도미회", 4000, "2-333");

                

                ac[4] = new MAccount("1414-11-6", "우럭회", 5000, 1000);

                ac[5] = new MAccount("4441-91-3", "육회", 6000, 2000);

                // ㄴ  6개의 계좌정ㅂ를 생성

                

                

                HashMap<String, Account> hashtable = new HashMap<String, Account>();

                HashKey tmphk;

                

                for(int i=0; i<ac.length; i++) {

                        tmphk = new HashKey(ac[i].ownerName, ac[i].getType());

                        hashtable.put(tmphk.toString(), ac[i]);

                        


                }

                // ㄴ 해쉬테이블에 6개 데이터 저장         




                

                LinkedList<QData> que = new LinkedList<QData>();

                

                String yn = null;

                String str = null;

                String name = null;

                String wType = null;

                String aType = null;

                String adder = null;

                int money =0;

                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));           

                QData qdata;

                

                System.out.printf("작업 하시겠습니까?(y/n) : ");

                

                try {            

                        yn = reader.readLine();


                        if(yn.equals("y")) {

                                while(true){

                                        

                                        System.out.printf("작업종류 \n1.입금  \n2.출금 \n3.신규: ");

                                        wType = reader.readLine();

                                        System.out.printf("이름 : ");

                                        name = reader.readLine();

                                        System.out.printf("금액 : ");

                                        money = Integer.parseInt(reader.readLine());

                                        System.out.printf("계좌종류 \n NORMAL / CHECK / MINUS : ");

                                        aType = reader.readLine();

                                        

                                        que.offer(new QData(wType, name, money, aType));

                                        // ㄴ 생성하여 큐에 저장

                                                

                                        System.out.printf("추가 데이터 입력 하시겠습니까?(y/n) : ");      

                                        yn = reader.readLine();


                                        if(yn.equals("n"))

                                                break;

                                        

                                                                                

                                }

                        } // ㄴ 작업 정보를 입력하면 큐에 넣는다.

                }

                catch(Exception e) {

                        System.err.println("키보드 입력 에러");

                }

                

                QData qtmp;

                HashKey htmp;

                Account tGet;

                

                while(!que.isEmpty()) {

                

                        qtmp = que.poll();

                        htmp = new HashKey(qtmp.name, qtmp.aType);

                        // ㄴ 큐에서 정보 꺼냄

                        

                        tGet = hashtable.get(htmp.toString());

                        // ㄴ 해쉬테이블에서 정보 꺼냄.

                        

                        if(qtmp.wType.equals("1")) {

                                tGet.balance += qtmp.money;

                                

                                hashtable.put(htmp.toString(), tGet);  

                        } // ㄴ  입금의 경우

                        if(qtmp.wType.equals("2")) {

                                try{

                                        if(tGet.balance - money < 0) {

                                                throw new Exception("가진돈보다 더 많이 입력했습니다");

                                        }

                                        tGet.balance -= qtmp.money;

                                        hashtable.put(htmp.toString(), tGet);                          

                                }

                                catch(Exception e) {

                                        String estr = e.getMessage();

                                        System.out.println(estr);

                                }

                        } // ㄴ 출금의 경우               

                        if(qtmp.wType.equals("3")) {

                                if(qtmp.aType.equals("NORMAL")) //NORMAL

                                        hashtable.put(htmp.toString(), new Account(Double.toString(Math.random()) , qtmp.name, qtmp.money));

                                if(qtmp.aType.equals("CHECK")) {  //CHECK

                                        try {

                                        System.out.printf("카드번호 : ");

                                        adder = reader.readLine();

                                        }

                                        catch(IOException e) {

                                                System.out.println("입출력오류");

                                        }

                                        Account ac1 = new CAccount(Double.toString(Math.random()) , qtmp.name, qtmp.money,Double.toString(Math.random() ));

                                        hashtable.put(htmp.toString(), ac1);                           

                                }

                                if(qtmp.aType.equals("MINUS")) { //MINUS

                                        try {

                                        System.out.printf("한도 : ");

                                        adder = reader.readLine();

                                        }

                                        catch(IOException e) {

                                                System.out.println("입출력오류");

                                        }                                       

                                        Account ac2 = new MAccount(Double.toString(Math.random()) , qtmp.name, qtmp.money, Integer.valueOf(adder) );

                                        hashtable.put(htmp.toString(), ac2);           

                                }

                        }

                         // ㄴ 신규의 경우

                }

                Account tGet1;

                

                System.out.printf("검색 하시겠습니까?(y/n) : ");

                

                try {            

                        yn = reader.readLine();

                }

                catch(IOException e) {

                        System.err.println("키보드 입력 에러");

                }       


                        if(yn.equals("y")) {

                                while(true){

                                        try {            

                                                System.out.printf("이름 : ");

                                                name = reader.readLine();

                                                System.out.printf("계좌종류 \n NORMAL / CHECK / MINUS : ");

                                                aType = reader.readLine();  

                                        }

                                        catch(IOException e) {

                                                System.err.println("키보드 입력 에러");

                                        }                       

                                        

                                        HashKey hk = new HashKey(name, aType);

                                        

                                        try{

                                                //데이터 찾아서 보여주기 시작

                                                tGet1 = hashtable.get(hk.toString());

                                                

                                                

                                                System.out.println("이름 : " + tGet1.ownerName);

                                                System.out.println("계좌번호 : " + tGet1.accountNo);

                                                System.out.println("잔액 : " + tGet1.balance);


                                        

                                                if(tGet1 instanceof CAccount) {

                                                        CAccount ca = (CAccount)tGet1;

                                                        System.out.println("카드번호 : " + ca.cardNo);

                                                }

                                                if(tGet1 instanceof MAccount) {

                                                        MAccount ma = (MAccount)tGet1;

                                                        System.out.println("마이너스 한도 : " + ma.minus);

                                                }

                                                //데이터 찾아서 보여주기 끝

                                                

                                                try{                                     

                                                        System.out.printf("추가 검색 하시겠습니까?(y/n) : ");     

                                                        yn = reader.readLine();

                                                }

                                                catch(IOException e) {

                                                        System.err.println("키보드 입력 에러");

                                                }       

                                                if(yn.equals("n"))

                                                        break;

                                        }

                                        catch(NullPointerException n) {

                                                System.out.println("그런 데이터가 없습니다");

                                        }

                                                                                

                                }

                        } // ㄴ 작업 정보를 입력하면 큐에 넣는다.

                }

}


 

 



<class Account>



public class Account {

        String accountNo;

        String ownerName;

        int balance;

        

        Account(String accountNo, String ownerName, int balance){

                this.accountNo = accountNo;

                this.ownerName = ownerName;

                this.balance = balance;

        }

        public void deposit(int amount){

                balance += amount;

        }

        public int withdraw(int amount) throws Exception{

                if(balance < amount)

                        throw new Exception("잔액이 부족");

                balance -= amount;

                return amount;

        }

        public String toString(){

                String acc = "accountNo:" + accountNo + " /ownername:" + ownerName+ " /balance:" + balance;

                return acc;

        }

        public String getType() {

                return "NORMAL";

        }


}


 

 


<class CAccount>



public class CAccount extends Account {

        String cardNo;

        CAccount(String accountNo, String ownerName, int balance, String cardNo){

                super(accountNo, ownerName, balance);

                this.cardNo = cardNo;

        }

        public int pay(String cardNo, int amount) throws Exception{

                if(!cardNo.equals(this.cardNo) || (balance < amount))

                        throw new Exception("지불이 불가능");

                return withdraw(amount);

        }

        

        public Object clone(){

                try{

                        return super.clone();

                }

                catch (CloneNotSupportedException e){

                        return null;

                }

        }

        public String toString(){

                String CA = "AccountNo:" + accountNo + "OwnerName" + ownerName + "Balance " + balance + "CardNo" + cardNo;

                return CA;

        }

        public String getType() {

                return "CHECK";

        }

}


 

 


<class MAccount>



public class MAccount extends Account {

        int minus;

        

        MAccount(String accountNo, String ownerName, int balance, int minus) {

                super(accountNo, ownerName, balance);

                this.minus = minus;

        }

        public int withdraw(int amount) throws Exception {

                if((balance+minus) < amount)

                        throw new Exception("인출 불가");

                balance -= amount;

                return amount;

        }

        public String getType() {

                return "MINUS";

        }

}

 

 



<class HashKey>


public class HashKey {

        String name;

        String aType;

        

        HashKey(String name, String aType) {

                this.name = name;

                this.aType = aType;

        }

        public String toString(){

                String acc = name + aType;

                return acc;

        }

        

}

 

 



<class QData>


public class QData {

        String name;

        int money;

        String aType;

        String wType;

        

        QData(String wType, String name, int money, String aType) {

                this.wType = wType;

                this.name = name;

                this.money = money;

                this.aType = aType;

        }


}

 


<실행화면>




1. 제대로 되는 경우  

 

 

은행 계좌관리 프로그램 정상작동

 

 

 

 

2. 없는사람 찾을 경우 익셉션

 

 

은행 계좌 관리 시뮬레이션 자바 소프트웨어 데이터 익셉션

 

 


3. 잔액부족시 익셉션 발생

 

 

은행 계좌 관리 시뮬레이션 자바 소프트웨어 잔액 익셉션