diff --git a/Week2/Account.java b/Week2/Account.java new file mode 100644 index 0000000..81400ec --- /dev/null +++ b/Week2/Account.java @@ -0,0 +1,15 @@ +package Week2; + +import java.math.BigDecimal; + +public interface Account { // + String getAccountInfo(); + void withdraw(BigDecimal value); + void deposit(BigDecimal value); + String getAccountNumber(); + AccountType getAccountType(); + BigDecimal getBalance(); + void eraseStringBuilder(); + +// void setBalance(BigDecimal balance); +} \ No newline at end of file diff --git a/Week2/Account/Account.java b/Week2/Account/Account.java new file mode 100644 index 0000000..b295d66 --- /dev/null +++ b/Week2/Account/Account.java @@ -0,0 +1,15 @@ +package Week2.Account; + +import java.math.BigDecimal; + +public interface Account { // + String getAccountInfo(); + void withdraw(BigDecimal value); + void deposit(BigDecimal value); + String getAccountNumber(); + AccountType getAccountType(); + BigDecimal getBalance(); + void eraseStringBuilder(); + boolean isActivated(); + +} \ No newline at end of file diff --git a/Week2/Account/AccountType.java b/Week2/Account/AccountType.java new file mode 100644 index 0000000..d994f4d --- /dev/null +++ b/Week2/Account/AccountType.java @@ -0,0 +1,15 @@ +package Week2.Account; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +//@AllArgsConstructor +public enum AccountType { + NORMAL_ACCOUNT("예금 계좌"), + SAVING_ACCOUNT("적금 계좌"); + + private final String accountName; +} \ No newline at end of file diff --git a/Week2/Account/BasicAccount.java b/Week2/Account/BasicAccount.java new file mode 100644 index 0000000..327fbf1 --- /dev/null +++ b/Week2/Account/BasicAccount.java @@ -0,0 +1,55 @@ +package Week2.Account; + +import java.math.BigDecimal; + +import Week2.Account.Account; +import Week2.Account.AccountType; +import lombok.*; + +@Getter +@Builder +@AllArgsConstructor +//@RequiredArgsConstructor +@NoArgsConstructor +public class BasicAccount implements Account { + + private final StringBuilder stringBuilder = new StringBuilder(); + private AccountType accountType; // 계좌 종류 + private String accountNumber; // 계좌번호 + private String owner; // 소유자 + private BigDecimal balance; // 잔액 + private boolean isActivated; // 활성화 여부 +// +// public BasicAccount(AccountType accountType, String accountNumber, String owner, BigDecimal balance, boolean isActivated) { +// this.stringBuilder = new StringBuilder(); +// this.accountType = accountType; +// this.accountNumber = accountNumber; +// this.owner = owner; +// this.balance = balance; +// this.isActivated = isActivated; +// } + public String getAccountInfo() { + stringBuilder.append("[계좌 정보]").append("\n"); + stringBuilder.append("계좌종류: ").append(accountType.getAccountName()).append("\n"); + stringBuilder.append("계좌번호: ").append(getAccountNumber()).append("\n"); + stringBuilder.append("소유자: ").append(getOwner()).append("\n"); + stringBuilder.append("잔액: ").append(getBalance()).append("\n"); + stringBuilder.append("활성여부: ").append(isActivated()); + return stringBuilder.toString(); + } + public void eraseStringBuilder(){ + this.stringBuilder.setLength(0); + } + + public void setBalance(BigDecimal balance) { this.balance = balance;} + + public void withdraw(BigDecimal value) { + setBalance(balance.subtract((value))); + } + + public void deposit(BigDecimal value) { + this.balance=this.balance.add(value); + } + + +} \ No newline at end of file diff --git a/Week2/Account/SavingAccount.java b/Week2/Account/SavingAccount.java new file mode 100644 index 0000000..6c11892 --- /dev/null +++ b/Week2/Account/SavingAccount.java @@ -0,0 +1,42 @@ +package Week2.Account; + +// TODO: 구현 + +import lombok.Getter; + + +import java.math.BigDecimal; + +@Getter +public class SavingAccount extends BasicAccount { + private BigDecimal targetAmount; + + public SavingAccount(AccountType accountType, String accountNumber, String owner, BigDecimal balance, boolean isActivated, BigDecimal targetAmount ) { + super( accountType, accountNumber, owner, balance, isActivated); + this.targetAmount = targetAmount; + } + + @Override + public String getAccountInfo() { + return super.getAccountInfo() + "\n목표 금액: " + targetAmount + "\n" ; + } + +// public BigDecimal getTargetAmount() { +// return targetAmount; +// } +// public void setBalance(BigDecimal balance) { super.setBalance(balance);} + + public void setTargetAmount(BigDecimal targetAmount) { + this.targetAmount = targetAmount; + } + + public void withdraw(BigDecimal value) { + BigDecimal target = getTargetAmount(); + int temp = getBalance().compareTo(target.multiply(BigDecimal.valueOf(0.01))); + if(temp > 0) { + setBalance(getBalance().subtract((value))); + } + } + + +} \ No newline at end of file diff --git a/Week2/AccountType.java b/Week2/AccountType.java new file mode 100644 index 0000000..e81819a --- /dev/null +++ b/Week2/AccountType.java @@ -0,0 +1,15 @@ +package Week2; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +//@RequiredArgsConstructor +@AllArgsConstructor +public enum AccountType { + NORMAL_ACCOUNT("예금 계좌"), + SAVING_ACCOUNT("적금 계좌"); + + private final String accountName; +} \ No newline at end of file diff --git a/Week2/Bank.java b/Week2/Bank.java new file mode 100644 index 0000000..31f2778 --- /dev/null +++ b/Week2/Bank.java @@ -0,0 +1,118 @@ +package Week2; + +import java.util.*; +import java.math.BigDecimal; +// 계좌생성, 출금, 입금, 송금 메서드 구현 +// 내부에서 입력을 받는 액션? +// 적금 계좌는 +public class Bank { + private ArrayList accountArray; + private HashMap interestCalculator; + + public Bank(){ + this.accountArray = new ArrayList<>(); + this.interestCalculator = new HashMap<>(); + this.interestCalculator.put(AccountType.NORMAL_ACCOUNT, new NormalInterestCalculator()); + this.interestCalculator.put(AccountType.SAVING_ACCOUNT, new SavingInterestCalculator()); + } + + // 계좌생성 + // 한 메소드안에 NORMAL과 SAVING을 같이 넣을려했지만 매개변수 이슈로 나눔 + public void createAccount(AccountType accountType, String accountNumber, String owner, + BigDecimal balance, boolean isActivated ){ + + BasicAccount account = new BasicAccount(accountType, accountNumber, owner, balance, isActivated); + accountArray.add(account); + + } + public void createAccount(AccountType accountType, String accountNumber, String owner, + BigDecimal balance, boolean isActivated,String targetAmount ){ + + SavingAccount account = new SavingAccount(accountType, accountNumber, owner, balance, isActivated, targetAmount); + accountArray.add(account); + } + + // 입금 + public void deposit(String accountNumber, BigDecimal money){ + + for (int i = 0; i < accountArray.size(); i++){ +// System.out.println(i); + if( accountArray.get(i).getAccountNumber().equals(accountNumber)) { + accountArray.get(i).deposit(money); + break; + } + if( i == accountArray.size()-1){ + System.out.println(accountNumber+"계좌 없음"); + } + } + + } + // 출금 + public void withdraw(String accountNumber, BigDecimal money){ + for (int i = 0; i < accountArray.size(); i++){ + if( accountArray.get(i).getAccountNumber().equals(accountNumber)) { + accountArray.get(i).withdraw(money); + break; + } + if( i == accountArray.size()-1){ + System.out.println(accountNumber+"계좌 없음"); + } + } + + } + // 송금 + public void remittance(String accountNumber, String targetAccountNumber,BigDecimal money){ + int Switch = 0; + for (int i = 0; i < accountArray.size(); i++){ + if( accountArray.get(i).getAccountNumber().equals(accountNumber)) { + accountArray.get(i).withdraw(money); + } + for (int j = 0; j < accountArray.size(); j++){ + if( accountArray.get(j).getAccountNumber().equals(targetAccountNumber)) { + accountArray.get(j).deposit(money); + Switch = 1; + break; + } + } + if (Switch == 1) + break; + + + } + } + + public void getAccountInfo(String accountNumber){ + + for (int i = 0; i < accountArray.size(); i++){ + if( accountArray.get(i).getAccountNumber().equals(accountNumber)) { + System.out.println(accountArray.get(i).getAccountInfo()); + System.out.println(); + accountArray.get(i).eraseStringBuilder(); + break; + } + if( i == accountArray.size()-1){ + System.out.println(accountNumber+"계좌 없음"); + } + } + } + +// 이자금액 반환 +// 계좌번호로 NORMAL인지 SAVING인지 확인 +// 확인 후 Type에 맞는 Hashmap 메소드 사용 + public void getInterest(String accountNumber){ + + for (int i = 0; i < accountArray.size(); i++){ + if( accountArray.get(i).getAccountNumber().equals(accountNumber)) { + if( accountArray.get(i).getAccountType().equals(AccountType.NORMAL_ACCOUNT) ){ + System.out.println("이자금액 : " + this.interestCalculator.get(AccountType.NORMAL_ACCOUNT).getInterest(accountArray.get(i).getBalance())); + } else if( accountArray.get(i).getAccountType().equals(AccountType.SAVING_ACCOUNT) ){ + System.out.println("이자금액 : " + this.interestCalculator.get(AccountType.SAVING_ACCOUNT).getInterest(accountArray.get(i).getBalance())); + } + } + } + + } + + + +} diff --git a/Week2/BankingApplication.java b/Week2/BankingApplication.java new file mode 100644 index 0000000..5ab0adb --- /dev/null +++ b/Week2/BankingApplication.java @@ -0,0 +1,11 @@ +package Week2; + +import Week2.SetBank.UI; + +public class BankingApplication { + public static void main(String[] args) { + + UI u = new UI(); + u.userView(); + }C:\Users\qq875\OneDrive\바탕 화면\JAVA\Java_COW\src\Week2 +} \ No newline at end of file diff --git a/Week2/BasicAccount.java b/Week2/BasicAccount.java new file mode 100644 index 0000000..e1dba2b --- /dev/null +++ b/Week2/BasicAccount.java @@ -0,0 +1,62 @@ +package Week2; + +import java.math.BigDecimal; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PROTECTED) // 접근 지정자 변경 +public class BasicAccount implements Account { + + private final StringBuilder stringBuilder; + + private AccountType accountType; // 계좌 종류 + + private String accountNumber; // 계좌번호 + + private String owner; // 소유자 + + private BigDecimal balance; // 잔액 + + private boolean isActivated; // 활성화 여부 + + + public BasicAccount(AccountType accountType, String accountNumber, String owner, BigDecimal balance, boolean isActivated) { + this.stringBuilder = new StringBuilder(); + this.accountType = accountType; + this.accountNumber = accountNumber; + this.owner = owner; + this.balance = balance; + this.isActivated = isActivated; + } + public String getAccountInfo() { + stringBuilder.append("[계좌 정보]").append("\n"); + stringBuilder.append("계좌종류: ").append(accountType.getAccountName()).append("\n"); + stringBuilder.append("계좌번호: ").append(getAccountNumber()).append("\n"); + stringBuilder.append("소유자: ").append(getOwner()).append("\n"); + stringBuilder.append("잔액: ").append(getBalance()).append("\n"); + stringBuilder.append("활성여부: ").append(isActivated()); + return stringBuilder.toString(); + } + public void eraseStringBuilder(){ + this.stringBuilder.setLength(0); + } +// public AccountType getAccountType() { return accountType;} + public void setBalance(BigDecimal balance) { this.balance = balance;} + + public void withdraw(BigDecimal value) { + setBalance(balance.subtract((value))); +// this.balance=this.balance.subtract(value); +// System.out.println("withdraw"+getBalance()); + } + + public void deposit(BigDecimal value) { + this.balance=this.balance.add(value); +// System.out.println("deposit"+this.getBalance()); + } + +} \ No newline at end of file diff --git a/Week2/InterestCalculator.java b/Week2/InterestCalculator.java new file mode 100644 index 0000000..f34e0e0 --- /dev/null +++ b/Week2/InterestCalculator.java @@ -0,0 +1,10 @@ +package Week2; + +import java.math.BigDecimal; +public interface InterestCalculator { + + BigDecimal getInterest(BigDecimal balance); // 계좌 잔액에 대한 이자금액 반환 + + + +} diff --git a/Week2/InterestCalculator/InterestCalculator.java b/Week2/InterestCalculator/InterestCalculator.java new file mode 100644 index 0000000..0e3541b --- /dev/null +++ b/Week2/InterestCalculator/InterestCalculator.java @@ -0,0 +1,10 @@ +package Week2.InterestCalculator; + +import java.math.BigDecimal; +public interface InterestCalculator { + + BigDecimal getInterest(BigDecimal balance); // 계좌 잔액에 대한 이자금액 반환 + + + +} diff --git a/Week2/InterestCalculator/NormalInterestCalculator.java b/Week2/InterestCalculator/NormalInterestCalculator.java new file mode 100644 index 0000000..a20f9e6 --- /dev/null +++ b/Week2/InterestCalculator/NormalInterestCalculator.java @@ -0,0 +1,36 @@ +package Week2.InterestCalculator; + +import Week2.InterestCalculator.InterestCalculator; + +import java.math.BigDecimal; + +public class NormalInterestCalculator implements InterestCalculator { + + // 1000만원이상은 이자율 50%, 500만원 이상은 7%, 100만원 이상은 4%, 1만원 이상은 2%, 그 외에는 1% + public BigDecimal getInterest(BigDecimal balance){ // 계좌 잔액에 대한 이자금액 반환 + + // 1590이면 1000으로 바꾸고 159면 100으로 바꿔서 하면 되나? + String toStringBalance = balance.toString(); + char head = toStringBalance.charAt(0); + int digit = toStringBalance.length()-1; + String temp = head + "0".repeat(digit); + int condition = Integer.parseInt(temp); + switch (condition ){ + case 500: case 600: case 700: case 800: case 900: + return balance.multiply(BigDecimal.valueOf(0.07)); + case 100: case 200: case 300: case 400: + return balance.multiply(BigDecimal.valueOf(0.04)); + default: + if (condition < 100 && condition >= 1) { + return balance.multiply(BigDecimal.valueOf(0.02)); + } else { + if (condition >= 1000) { + return balance.multiply(BigDecimal.valueOf(0.5)); + } else { + return balance.multiply(BigDecimal.valueOf(0.01)); + } + } + } + } + +} \ No newline at end of file diff --git a/Week2/InterestCalculator/SavingInterestCalculator.java b/Week2/InterestCalculator/SavingInterestCalculator.java new file mode 100644 index 0000000..610ba39 --- /dev/null +++ b/Week2/InterestCalculator/SavingInterestCalculator.java @@ -0,0 +1,18 @@ +package Week2.InterestCalculator; + +import Week2.InterestCalculator.InterestCalculator; + +import java.math.BigDecimal; + +public class SavingInterestCalculator implements InterestCalculator { + + // 100만원 이상은 이자율 50%, 그외에는 1% + public BigDecimal getInterest(BigDecimal balance){ // 계좌 잔액에 대한 이자금액 반환 + + if ( balance.compareTo(BigDecimal.valueOf(100)) >= 0) + return balance.multiply(BigDecimal.valueOf(0.5)); + else + return balance.multiply(BigDecimal.valueOf(0.01)); + } + +} \ No newline at end of file diff --git a/Week2/NormalInterestCalculator.java b/Week2/NormalInterestCalculator.java new file mode 100644 index 0000000..3bd781a --- /dev/null +++ b/Week2/NormalInterestCalculator.java @@ -0,0 +1,23 @@ +package Week2; + +import java.math.BigDecimal; + +public class NormalInterestCalculator implements InterestCalculator{ + + // 1000만원이상은 이자율 50%, 500만원 이상은 7%, 100만원 이상은 4%, 1만원 이상은 2%, 그 외에는 1% + public BigDecimal getInterest(BigDecimal balance){ // 계좌 잔액에 대한 이자금액 반환 + + if( balance.compareTo(BigDecimal.valueOf(1000)) >= 0 ) + return balance.multiply(BigDecimal.valueOf(0.5)); + else if ( balance.compareTo(BigDecimal.valueOf(500)) >= 0) + return balance.multiply(BigDecimal.valueOf(0.07)); + else if ( balance.compareTo(BigDecimal.valueOf(100)) >= 0) + return balance.multiply(BigDecimal.valueOf(0.04)); + else if( balance.compareTo(BigDecimal.ONE) >= 0) + return balance.multiply(BigDecimal.valueOf(0.02)); + else + return balance.multiply(BigDecimal.valueOf(0.01)); + + } + +} \ No newline at end of file diff --git a/Week2/SavingAccount.java b/Week2/SavingAccount.java new file mode 100644 index 0000000..c397a60 --- /dev/null +++ b/Week2/SavingAccount.java @@ -0,0 +1,41 @@ +package Week2; + +// TODO: 구현 +import lombok.*; +import java.math.BigDecimal; + +public class SavingAccount extends BasicAccount{ + private String targetAmount; + + public SavingAccount(AccountType accountType, String accountNumber, String owner, BigDecimal balance, boolean isActivated,String targetAmount ) { + super( accountType, accountNumber, owner, balance, isActivated); + this.targetAmount = targetAmount; + } + +// public String getAccountNumber() { return accountNumber;} + @Override + public String getAccountInfo() { + return super.getAccountInfo() + "\n목표 금액: " + targetAmount + "\n" ; + } + + public String getTargetAmount() { + return targetAmount; + } + public void setBalance(BigDecimal balance) { super.setBalance(balance);} + + public void setTargetAmount(String targetAmount) { + this.targetAmount = targetAmount; + } + + public void withdraw(BigDecimal value) { + BigDecimal target = new BigDecimal(getTargetAmount()); + int temp = getBalance().compareTo(target.multiply(BigDecimal.valueOf(0.01))); + if(temp>0) { + setBalance(getBalance().subtract((value))); +// this.balance=this.balance.subtract(value); +// System.out.println("withdraw"+getBalance()); + } + } + + +} \ No newline at end of file diff --git a/Week2/SavingInterestCalculator.java b/Week2/SavingInterestCalculator.java new file mode 100644 index 0000000..9188c2d --- /dev/null +++ b/Week2/SavingInterestCalculator.java @@ -0,0 +1,16 @@ +package Week2; + +import java.math.BigDecimal; + +public class SavingInterestCalculator implements InterestCalculator{ + + // 100만원 이상은 이자율 50%, 그외에는 1% + public BigDecimal getInterest(BigDecimal balance){ // 계좌 잔액에 대한 이자금액 반환 + + if ( balance.compareTo(BigDecimal.valueOf(100)) >= 0) + return balance.multiply(BigDecimal.valueOf(0.5)); + else + return balance.multiply(BigDecimal.valueOf(0.01)); + } + +} \ No newline at end of file diff --git a/Week2/SetBank/Bank.java b/Week2/SetBank/Bank.java new file mode 100644 index 0000000..465a60c --- /dev/null +++ b/Week2/SetBank/Bank.java @@ -0,0 +1,183 @@ +package Week2.SetBank; + +import Week2.Account.Account; +import Week2.Account.AccountType; +import Week2.Account.BasicAccount; +import Week2.Account.SavingAccount; +import Week2.InterestCalculator.InterestCalculator; +import Week2.InterestCalculator.NormalInterestCalculator; +import Week2.InterestCalculator.SavingInterestCalculator; + +import java.util.*; +import java.math.BigDecimal; + +public class Bank extends InputAccount { + private ArrayList accounts = new ArrayList<>(); + private HashMap interestCalculator = new HashMap<>(); + + public Bank(){ + this.interestCalculator.put(AccountType.NORMAL_ACCOUNT, new NormalInterestCalculator()); + this.interestCalculator.put(AccountType.SAVING_ACCOUNT, new SavingInterestCalculator()); + System.out.println("Bank생성자"); + } + + public void createBasicAccount( ){ + + AccountType accountType = AccountType.NORMAL_ACCOUNT; + String accountNumber = this.inputAccountNumber(); + String owner = this.inputOwner(); + BigDecimal balance = this.inputBalance(); + boolean isActivated = this.inputIsActivated(); + + BasicAccount account = new BasicAccount(accountType, accountNumber, owner, balance, isActivated); + accounts.add(account); + } + public void createSavingAccount(){ + + AccountType accountType = AccountType.SAVING_ACCOUNT; + String accountNumber = this.inputAccountNumber(); + String owner = this.inputOwner(); + BigDecimal balance = this.inputBalance(); + boolean isActivated = this.inputIsActivated(); + BigDecimal targetAmount = this.inputTargetAmount(); + + SavingAccount account = new SavingAccount(accountType, accountNumber, owner, balance, isActivated, targetAmount); + accounts.add(account); + } + + // 입금 + public void deposit(String accountNumber, BigDecimal money){ + + boolean success = false; + + for( Account account : accounts){ + if( account.getAccountNumber().equals(accountNumber) ) { + account.deposit(money); + success = true; + break; + } + } + if( !success ){ + System.out.println("계좌 없음"); + } + } + // 출금 + public void withdraw(String accountNumber, BigDecimal money){ + + boolean success = false; + + for( Account account : accounts){ + if( account.getAccountNumber().equals(accountNumber)) { + account.withdraw(money); + success = true; + break; + } + } + if( !success ){ + System.out.println("계좌 없음"); + } + } + // 송금 + public void remittance(String accountNumber, String targetAccountNumber,BigDecimal money) { + + boolean balance_A = false; // 출금계좌의 돈이 충분한지 + boolean find_A = false; // 출금계좌 존재여부 + boolean find_B = false; // 입금계좌 존재여부 + boolean isActivated_A = false; + boolean isActivated_B= false; + + Account A = null; // 출금계좌 정보담음 + Account B = null; // 입금계좌 정보담음 + + // 양쪽 계좌가 존재하면서 송금하는 계좌의 돈이 충분해야 송금이 가능하도록 + for (Account account : accounts) { + if (account.getAccountNumber().equals(accountNumber)) { + A = account; + find_A = true; + if( account.getBalance().compareTo(money) >= 0 ){ + balance_A = true; + } + break; + } + } + if( isActivated_A ) { + return; + } + + if( !balance_A ){ + System.out.println("출금 계좌 잔액 부족"); + return; + } else if( !find_A ){ + System.out.println("출금 계좌 검색 실패"); + return; + } + + if (find_A) { + for (Account account : accounts) { + if (account.getAccountNumber().equals(targetAccountNumber)) { + B=account; + find_B = true; + break; + } + } + } + + if( isActivated_B ){ + return; + } + if( !find_B ){ + System.out.println("입금 계좌 검색 실패"); + return; + } + + if( find_A && find_B){ + A.withdraw(money); + B.deposit(money); + System.out.println("이체 성공"); + } + } + public void getAccountInfo(String accountNumber){ + for(Account account : accounts ){ + if(account.getAccountNumber().equals(accountNumber) ){ + System.out.println(account.getAccountInfo()); + System.out.println(); + account.eraseStringBuilder(); + break; + } + } + } + + public void getInterest(String accountNumber){ + + for( Account account : accounts ){ + if(account.getAccountNumber().equals(accountNumber) ){ + if(account.getAccountType().equals(AccountType.NORMAL_ACCOUNT)){ + System.out.println("이자금액 : " + this.interestCalculator.get(AccountType.NORMAL_ACCOUNT).getInterest(account.getBalance())); + } else { + System.out.println("이자금액 : " + this.interestCalculator.get(AccountType.SAVING_ACCOUNT).getInterest(account.getBalance())); + } + } + } + } + + public Integer isHaveAccount(){ + + int isHave = accounts.size(); + + return isHave; + } + + public boolean IsActivated(String accountNumber) { + + for( Account account : accounts ) { + if (account.getAccountNumber().equals(accountNumber)) { + if (account.isActivated() == true) { + return true; + } else { + return false; + } + } + } + return false; + } +} diff --git a/Week2/SetBank/InputAccount.java b/Week2/SetBank/InputAccount.java new file mode 100644 index 0000000..79676fc --- /dev/null +++ b/Week2/SetBank/InputAccount.java @@ -0,0 +1,56 @@ +package Week2.SetBank; + +import java.math.BigDecimal; +import java.util.Scanner; + +public class InputAccount { + private Scanner s = new Scanner(System.in); + public String inputAccountNumber(){ + System.out.print("계좌번호 : "); + + int temp = s.nextInt(); + s.nextLine(); + + return String.valueOf(temp); + } + + public String inputOwner(){ + System.out.print("소유자명 : "); + + String temp = s.nextLine(); + + return temp; + } + + public BigDecimal inputBalance(){ + System.out.print("잔고 : "); + + BigDecimal b = s.nextBigDecimal(); + + return b; + } + + public boolean inputIsActivated(){ + System.out.print("활성 여부(Y/N) : "); + + String temp = s.next(); + s.nextLine(); + + if( temp.equals("Y")){ + return true; + } else { + return false; + } + } + + public BigDecimal inputTargetAmount(){ + System.out.print("목표금액 : "); + + BigDecimal b = s.nextBigDecimal(); + s.nextLine(); + + return b; + } + + +} diff --git a/Week2/SetBank/UI.java b/Week2/SetBank/UI.java new file mode 100644 index 0000000..61f7324 --- /dev/null +++ b/Week2/SetBank/UI.java @@ -0,0 +1,135 @@ +package Week2.SetBank; + +import Week2.SetBank.Bank; + +import java.math.BigDecimal; +import java.util.InputMismatchException; +import java.util.Scanner; + + +public class UI extends Bank { + private Scanner scanner = new Scanner(System.in); + + // 1. 송금 2. 출금 3. 계좌찾기 이런식으로해서 해야할듯 + // 3누르면 계좌번호 입력하라고뜨고 그 계좌번호를 가지고있는 account찾아서 정보 출력 + + public void userView() { + boolean turnOff = false; + String temp; + BigDecimal money; + int number; + int temp_int; + int temp2_int; + + while(true) { + try { + System.out.print("1. 계좌 등록\t2. 출금\t3. 입금\t4. 송금\t5. 계좌정보\t6. 이자금액\t 0. 종료 : "); + number = scanner.nextInt(); + scanner.nextLine(); + + if( isHaveAccount() == 0 ){ // 등록된 계좌가 없을 때 발생 + if( number >= 2 && number <= 6) { + System.out.print("계좌가 없습니다. "); + throw new Exception(); + } + } else if ( isHaveAccount() == 1){ // 등록된 계좌가 한개일때 송금 못함 + if( number == 4){ + System.out.println("입력된 계좌가 1개 있습니다. "); + throw new Exception(); + } + } + + switch (number) { + case 0: + turnOff = true; + break; + case 1: // 계좌등록 + System.out.print("계좌종류(N or S) : "); + temp = scanner.next(); + scanner.nextLine(); + + if (temp.equals("S")) { + this.createSavingAccount(); + } else if (temp.equals("N")) { + this.createBasicAccount(); + } else { + System.out.println("다시 입력하세요"); + continue; + } + break; + case 2: // 출금 + System.out.print("계좌번호 입력 : "); + temp_int = scanner.nextInt(); + scanner.nextLine(); + if( !IsActivated(Integer.toString(temp_int))) { + System.out.println("비활성화 계좌입니다"); + break; + } + System.out.print("출금할 금액 : "); + money = scanner.nextBigDecimal(); + this.withdraw(Integer.toString(temp_int), money); + break; + + case 3: // 입금 + System.out.print("계좌번호 입력 : "); + temp_int = scanner.nextInt(); + scanner.nextLine(); + if( !IsActivated(Integer.toString(temp_int)) ) { + System.out.println("비활성화 계좌입니다"); + break; + } + System.out.print("입금할 금액 : "); + money = scanner.nextBigDecimal(); + this.deposit(Integer.toString(temp_int), money); + break; + + case 4: // 송금 + System.out.print("출금 계좌번호 입력 : "); + temp_int = scanner.nextInt(); + scanner.nextLine(); + if( !IsActivated(Integer.toString(temp_int))) { + System.out.println("비활성화 계좌입니다"); + break; + } + System.out.print("입금 계좌번호 입력 : "); + temp2_int = scanner.nextInt(); + scanner.nextLine(); + if( !IsActivated(Integer.toString(temp2_int))) { + System.out.println("비활성화 계좌입니다"); + break; + } + System.out.print("보낼 금액 : "); + money = scanner.nextBigDecimal(); + this.remittance(Integer.toString(temp_int), Integer.toString(temp2_int), money); + break; + case 5: // 계좌정보 + System.out.print("계좌번호 입력 : "); + temp_int = scanner.nextInt(); + scanner.nextLine(); + this.getAccountInfo(Integer.toString(temp_int)); + break; + case 6: // 이자 + System.out.print("계좌번호 입력 : "); + temp_int = scanner.nextInt(); + scanner.nextLine(); + this.getInterest(Integer.toString(temp_int)); + break; + default: + System.out.println("다시 입력하시오"); + } + if (turnOff) { // 0 입력시 turnOff true로 + System.out.println("종료합니다"); + break; + } + } + catch (InputMismatchException e){ + System.out.println("다시 입력하세요"); + scanner.nextLine(); + } + catch(Exception e){ + System.out.println("다시 입력하세요"); + } + } + scanner.close(); + } +}