Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2주차]객체지향 코드 연습(Juuuu-power-e) #11

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions BankingSystem/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions BankingSystem/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions BankingSystem/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions BankingSystem/.idea/practice-oop-banking.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions BankingSystem/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions BankingSystem/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions BankingSystem/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package BankingSystem;

import BankingSystem.bank.Bank;
import BankingSystem.bank.CentralBank;
import BankingSystem.utility.Dialog;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Dialog.scanner = new Scanner(System.in);
//Bank의 parameter로 scanner를 넘기는것과 이 방식중 뭐가 더 나은지 고민..

CentralBank centralBank = new CentralBank();
Bank bank = new Bank();
bank.associate(centralBank);
bank.run();
bank.payInterest();
bank.run();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적인 실행 흐름을 Bank 클래스가 관리하고 있는데, 이렇게 되면 Bank의 역할이 너무 커져 추후 수정이 어려워질 수 있습니다. 실행 흐름을 따로 관리하는 역할을 하는 클래스를 만들어서 어떻게 관리할 수 있을까요?



}
12 changes: 12 additions & 0 deletions BankingSystem/MyException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package BankingSystem;

public class MyException extends Exception{

enum EError{

}




}
108 changes: 108 additions & 0 deletions BankingSystem/account/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package BankingSystem.account;

import BankingSystem.utility.Dialog;

import java.math.BigDecimal;

public class Account {


protected EAccount eAccount;
protected String accountNum;
protected String accountHolder;
protected BigDecimal balance;
protected boolean isActivate;


public EAccount getEAccount() {
return eAccount;
}

public void setEAccount(EAccount eAccount) {
this.eAccount = eAccount;
}

public String getAccountNum() {
return accountNum;
}

public void setAccountNum(String accountNum) {
this.accountNum = accountNum;
}

public String getAccountHolder() {
return accountHolder;
}

public void setAccountHolder(String accountHolder) {
this.accountHolder = accountHolder;
}

public BigDecimal getBalance() {
return balance;
}

public void setBalance(BigDecimal balance) {
this.balance = balance;
}

public boolean isActivate() {
return isActivate;
}

public void setActivate(boolean activate) {
isActivate = activate;
}


public Account(){
this.eAccount = EAccount.N;
this.balance = new BigDecimal(0);
this.isActivate = true;
}

public Account(String accountHolder, String accountNum){
this();
this.accountHolder = accountHolder;
this.accountNum = accountNum;
}



public String getAccountInfo(){
return "계좌종류 : " + eAccount.menuName + "\n" +
"계좌번호 : " + accountNum + "\n" +
"예금주 : " + accountHolder + "\n" +
"잔액 : " + balance + "\n" +
"계좌상태 : " + (isActivate ? "활성화" : "비활성화");
}


public boolean deposit(BigDecimal amount){
if(balance.compareTo(amount)<0){
this.balance = balance.add(amount);
return true;
}
return false;
}

public boolean withdraw(BigDecimal amount){
try {
this.balance = balance.subtract(amount);
return true;
}catch (Exception e){
Dialog.systemMsg("오류가 발생했습니다. 다시 시도해주세요.");
return false;
}
}

public Account newAccount(){
return new Account();
}


}




46 changes: 46 additions & 0 deletions BankingSystem/account/EAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package BankingSystem.account;

public enum EAccount /*implements Selectable*/{
N("예금계좌", new Account()),
S("적금계좌", new SaveAccount());

public String getMenuName() {
return menuName;
}

final String menuName;
Account account;

// EAccount selectEAccount(int num){
// return EAccount.values()[num];
// }

// String[] getInformations(){
// String[] returnValue = new String[values().length];
// for (int i = 0; i < values().length; i++){
// returnValue[i] = values()[i].menuName;
// }
// return returnValue;
// }
EAccount(String menuName, Account account) {
this.menuName = menuName;
this.account = account;
}

public static String[] nameValues(){
int nOfValues = values().length;
String[] returnValue = new String[nOfValues];
for(int i = 0; i < nOfValues; i++){
returnValue[i] = values()[i].getMenuName();
}
return returnValue;
}


public Account getAccount(){
return this.account;
}
public int getAccountTypeCode(){
return this.ordinal();
}
}
Loading