2016. 9. 1. 22:11ㆍ프로그래밍/자바
import java.util.ArrayList;
import java.util.Scanner;
public class BankAccounts extends BankList {
public static void main(String[] args) {
boolean loop = true;
while(loop){
System.out.println("------------------------------------------------");
System.out.println("1.계좌 생성| 2. 계좌 조회 | 3. 입금 | 4.출금 | 5. 종료");
System.out.println("------------------------------------------------");
System.out.println("선택 : ");
Scanner sc = new Scanner(System.in);
int select = sc.nextInt();
if(select == 1){
createAcc();
}
else if(select == 2){
getAcc();
}
else if(select == 3){
depositAcc();
}
else if(select == 4){
withdrawAcc();
} else{
System.out.println("프로그램을 종료합니다");
sc.close();
loop = false;
}
}
}
public static void createAcc(){
System.out.println("계좌주 : ");
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
accName.add(name);
System.out.println("계좌번호 : ");
Scanner sc1 = new Scanner(System.in);
String number = sc1.nextLine();
accNumber.add(number);
System.out.println("초기입금액 : ");
Scanner sc2 = new Scanner(System.in);
int money = sc2.nextInt();
accMoney.add(money);
}
public static void getAcc(){
System.out.println("계좌번호를 입력하세요 : ");
Scanner sc = new Scanner(System.in);
String accNum = sc.nextLine();
int cnt =0;
if(accNumber.size()!=0){
for (int i = 0; i < accNumber.size(); i++) {
if(accNumber.get(i).equals(accNum)){
System.out.println("계좌주 : "+accName.get(i)+" 계좌번호 : "+accNumber.get(i)+
" 잔액 : "+accMoney.get(i));
} else {
cnt++;
continue;
}
}
if(cnt==accNumber.size()){
System.out.println("일치하는 계좌가 없습니다");
cnt=0;
}
}else {
System.out.println("계좌생성 후 조회하세요!");
}
}
public static void depositAcc(){
System.out.println("입금할 계좌번호를 입력하세요 : ");
Scanner sc = new Scanner(System.in);
String accNum = sc.nextLine();
int cnt = 0;
if(accNumber.size()!=0){
for (int i = 0; i < accNumber.size(); i++) {
if(accNumber.get(i).equals(accNum)){
System.out.println("입금할 금액을 입력하세요 : ");
Scanner sc1 = new Scanner(System.in);
int deposit = sc1.nextInt();
accMoney.set(i, accMoney.get(i)+deposit);
System.out.println("계좌주 : "+accName.get(i)+" 계좌번호 : " +accNumber.get(i)+
" 잔액 : "+accMoney.get(i));
} else {
cnt++;
continue;
}
}
if(cnt == accNumber.size()){
System.out.println("일치하는 계좌가 없습니다.");
cnt = 0;
}
}else {
System.out.println("계좌 등록 후 입금 하세요");
}
}
public static void withdrawAcc(){
System.out.println("출금할 계좌번호를 입력하세요 : ");
Scanner sc = new Scanner(System.in);
String accNum = sc.nextLine();
int cnt=0;
if(accNumber.size()!=0){
for (int i = 0; i < accNumber.size(); i++) {
if(accNumber.get(i).equals(accNum)){
System.out.println("출금할 금액을 입력하세요 : ");
Scanner sc1 = new Scanner(System.in);
int withdraw = sc1.nextInt();
if(withdraw <= accMoney.get(i)){
accMoney.set(i, accMoney.get(i)-withdraw);
System.out.println("계좌주 : "+accName.get(i)+" 계좌번호 : " +accNumber.get(i)+
" 잔액 : "+accMoney.get(i));
} else {
System.out.println("잔액이 부족합니다");
}
} else {
cnt++;
continue;
}
}
if(cnt==accNumber.size()){
System.out.println("일치하는 계좌가 없습니다!");
cnt=0;
}
}
}
}
import java.util.ArrayList;
public class BankList {
static ArrayList<String> accName = new ArrayList<>();
static ArrayList<String> accNumber = new ArrayList<>();
static ArrayList<Integer> accMoney = new ArrayList<>();
public static ArrayList<String> getAccName() {
return accName;
}
public static void setAccName(ArrayList<String> accName) {
BankList.accName = accName;
}
public static ArrayList<String> getAccNumber() {
return accNumber;
}
public static void setAccNumber(ArrayList<String> accNumber) {
BankList.accNumber = accNumber;
}
public static ArrayList<Integer> getAccMoney() {
return accMoney;
}
public static void setAccMoney(ArrayList<Integer> accMoney) {
BankList.accMoney = accMoney;
}
}
'프로그래밍 > 자바' 카테고리의 다른 글
은행계좌 Mysql 연동 (입금) (0) | 2016.09.05 |
---|---|
은행계좌 Mysql 연동 (계좌 생성+조회) (0) | 2016.09.05 |
indexOf 예제 (0) | 2016.08.29 |
배열 연습(arraylist) (0) | 2016.08.29 |
자바 arrayList 사용 (0) | 2016.08.28 |