-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Changes from all commits
ff81112
f02c4f7
d2b54fc
6370100
f77b071
d44abdb
782a92a
17653b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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(); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package BankingSystem; | ||
|
||
public class MyException extends Exception{ | ||
|
||
enum EError{ | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
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(); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전체적인 실행 흐름을 Bank 클래스가 관리하고 있는데, 이렇게 되면 Bank의 역할이 너무 커져 추후 수정이 어려워질 수 있습니다. 실행 흐름을 따로 관리하는 역할을 하는 클래스를 만들어서 어떻게 관리할 수 있을까요?