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

[week1] 1차 세미나 정규 과제 #2

Open
wants to merge 1 commit 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
89 changes: 88 additions & 1 deletion Assignment1/src/main/java/Controller/BankController.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,89 @@
package Controller;public class BankController {
package Controller;

import Service.BankService;
import Service.BankServiceImpl;

import java.util.Scanner;

import static java.lang.System.exit;

public class BankController {
public void entranceBank(){
BankService bankService = new BankServiceImpl();
Scanner sc = new Scanner(System.in);
while(true){
System.out.println();
System.out.println("원하시는 업무를 입력해주세요.");
System.out.println("[은행가입] [예적금] [잔액조회] [전체계좌조회] [나가기]");
String userInput = sc.nextLine().trim();
MainAction action = MainAction.findByAction(userInput);
if (action == null) {
System.out.println("!!!올바른 업무를 입력해주세요!!!");
continue;
}
switch (action) {
case JOIN_BANK ->{
System.out.print("이름을 입력해주세요 : ");
String name = sc.nextLine();;
System.out.print("주민번호 앞자리를 입력해주세요 : ");
String birth = sc.nextLine();
bankService.join(name, birth);
}
case SAVINGS -> {
System.out.println("원하시는 업무를 입력해주세요.");
System.out.println("[계좌이체] [입금] [출금]");
userInput = sc.nextLine();
SavingAction savingAction = SavingAction.findByAction(userInput);
if (savingAction == null) {
System.out.println("!!!올바른 업무를 입력해주세요!!!");
continue;
}
switch (savingAction){
case TRANSFER->{
//todo: 계좌이체 서비스
System.out.print("고객님의 이름을 입력해주세요: ");
String name = sc.nextLine();
System.out.print("고객님의 생년월일을 입력해주세요: ");
String birth = sc.nextLine();
if(bankService.checkMember(name, birth)){
System.out.print("송금할 계좌번호를 입력하세요: ");
int account = Integer.parseInt(sc.nextLine());
System.out.print("송금할 금액을 입력하세요: ");
int money = Integer.parseInt(sc.nextLine());
bankService.transfer(name, birth, money, account);
seokbeom00 marked this conversation as resolved.
Show resolved Hide resolved
}
}
case DEPOSIT ->{
System.out.print("입금할 계좌번호를 입력하세요: ");
int account = Integer.parseInt(sc.nextLine());
System.out.print("입금할 금액을 입력하세요: ");
int money = Integer.parseInt(sc.nextLine());
bankService.deposit(money, account);
}
case WITHDRAW ->{
System.out.print("출금할 계좌번호를 입력하세요: ");
int account = Integer.parseInt(sc.nextLine());
System.out.print("출금할 금액을 입력하세요: ");
int money = Integer.parseInt(sc.nextLine());
bankService.withdraw(money, account);
}
}
}
case SHOW_ALL_ACCOUNTS -> {
bankService.showAll();
}
case BALANCE -> {
System.out.print("고객님의 이름을 입력해주세요: ");
String name = sc.nextLine();
System.out.print("고객님의 생년월일을 입력해주세요: ");
String birth = sc.nextLine();
bankService.showBalance(name, birth);
}
case EXIT ->{
System.out.println("조심히 가십쇼.");
exit(0);
}
}
}
}
}
3 changes: 1 addition & 2 deletions Assignment1/src/main/java/Controller/MainAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ public enum MainAction {
JOIN_BANK("은행가입"),
SAVINGS("예적금"),
SHOW_ALL_ACCOUNTS("전체계좌조회"),
BALANCE("잔액조회"),
EXIT("나가기");

private final String action;

MainAction(String action) {
this.action = action;
}

public String getAction() {
return action;
}

public static MainAction findByAction(String action) {
for (MainAction value : values()) {
if (value.getAction().equalsIgnoreCase(action)) {
Expand Down
23 changes: 22 additions & 1 deletion Assignment1/src/main/java/Controller/SavingAction.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
package Controller;public enum SavingAction {
package Controller;

public enum SavingAction {
TRANSFER("계좌이체"),
DEPOSIT("입금"),
WITHDRAW("출금");
private final String action;

SavingAction(String action) {
this.action = action;
}
public String getAction() {
return action;
}
public static SavingAction findByAction(String action) {
for (SavingAction value : values()) {
if (value.getAction().equalsIgnoreCase(action)) {
return value;
}
}
return null;
}
seokbeom00 marked this conversation as resolved.
Show resolved Hide resolved
}
75 changes: 74 additions & 1 deletion Assignment1/src/main/java/Data/Member.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,75 @@
package Data;public class Member {
package Data;

import java.util.Date;

public class Member {
private Long id;
private String name;
private Date enterDate;
private String birth;
private int account;
private int balance;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getBirth() {
return birth;
}

public void setBirth(String birth) {
this.birth = birth;
}

public Date getEnterDate() {
return enterDate;
}

public void setEnterDate(Date enterDate) {
this.enterDate = enterDate;
}

public int getAccount() {
return account;
}

public void setAccount(int account) {
this.account = account;
}

public int getBalance() {
return balance;
}

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

@Override
public String toString() {
return "[고객ID] " + id +
" [이름] " + name +
" [생년월일] " + birth +
" [가입날짜] " + enterDate +
" [계좌번호] " + account +
" [잔액] " + balance +"원";
}

public Member(String name, String birth){
this.name = name;
this.birth = birth;
}
}
8 changes: 7 additions & 1 deletion Assignment1/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
package PACKAGE_NAME;public class Main {
import Controller.BankController;

public class Main {
public static void main(String[] args) {
BankController bankController = new BankController();
bankController.entranceBank();
}
}
17 changes: 16 additions & 1 deletion Assignment1/src/main/java/Repository/BankRepository.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
package Repository;public interface BankRepository {
package Repository;

import Data.Member;

import java.util.List;
import java.util.Optional;

public interface BankRepository {
Member join(Member member);
List<Member> findAll();

Optional<Member> findByAccount(int account);
Optional<Member> findMember(String name, String birth);
int deposit(Member member, int money);

void withdraw(Member member, int money);
}
45 changes: 38 additions & 7 deletions Assignment1/src/main/java/Repository/MemoryBankRepository.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
package Repository;

import Data.Member;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.*;

public class MemoryBankRepository {
private static HashMap<Long, Member> bank = new HashMap<>();
public class MemoryBankRepository implements BankRepository{
private static HashMap<Integer, Member> bank = new HashMap<>();
private static Long id = 0L;
public void join(Member member) {

@Override
public Member join(Member member) {
member.setId(id++);
bank.put(member.getId(), member);
member.setEnterDate(new Date());
member.setAccount((int)(Math.random()*10000000));
bank.put(member.getAccount(), member);
return member;
}

public List<Member> findAll(){
return new ArrayList<>(bank.values());
}

@Override
public Optional<Member> findByAccount(int account) {
return Optional.ofNullable(bank.get(account));
}


@Override
public Optional<Member> findMember(String name, String birth) {
Optional<Member> member = bank.values().stream()
.filter(m -> m.getName().equals(name) && m.getBirth().equals(birth))
.findAny();
return member;
}

@Override
public int deposit(Member member, int money) {
member.setBalance(member.getBalance()+money);
return member.getBalance();
}

@Override
public void withdraw(Member member, int money) {
member.setBalance(member.getBalance()-money);
}
}
17 changes: 16 additions & 1 deletion Assignment1/src/main/java/Service/BankService.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
package Service;public interface BankService {
package Service;

import Data.Member;

import java.util.List;

public interface BankService {
void join(String name, String birth);
void deposit(int money, int account);
void withdraw(int money, int account);
void showAll();
void showBalance(String name, String birth);

boolean checkMember(String name, String birth);

void transfer(String name, String birth, int money, int account);
}
Loading