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

[기본과제/심화과제] 1주차 자바 객체지향 개념/ 은행 구현하기 #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

hayounSong
Copy link
Collaborator


🐕 과제 구현 명세

👨‍💻 기본 과제

  • 자바의 객체지향 개념 코드로 구현하기
  • interface, 오버로딩, 오버라이딩, 클래스, 추상화, 상속, 다형성 등 자바의 필수적인 객체지향 개념을 코드로 구현하며 복습하였습니다.
  • 마지막으로 제네릭 까지 실습하며, 본격적인 스프링 학습전 자바 개념들을 복습하고 더욱 더 기본기를 탄탄히 할 수 있었어요

📕 심화 과제

  • 자바의 객체지향 개념을 이용하여, 은행이라는 interface를 만들어주고, 이를 implements 하여 사용하는 우리은행 클래스, 그리고 이러한 은행들을 사용하는 BankUser 클래스로 나누어 작성하였습니다!
public interface Bank {
    public abstract void deposit(int money);



    public abstract void withdraw(int money);
    public abstract void checkMoney();

}

먼저, 은행의 기본기능인 조회, 출금, 입금 기능을 가지고 있는 Bank InterFace를 구현해주었습니당

public class WooriBank implements Bank {

    int currentMoney;
    String telephone;
    String webUrl;

    public WooriBank(int currentMoney,String telephone,String webUrl){
        this.currentMoney=currentMoney;
        this.telephone=telephone;
        this.webUrl=webUrl;
        System.out.println("은행 생성완료!");
    }
    @Override
    public void deposit(int money) {
        this.currentMoney=this.currentMoney+money;
        System.out.println(money+"만큼 입금되었습니다!");
    }

    @Override
    public void withdraw(int money){
        if(this.currentMoney-money<0){
            System.out.println("잔고가 부족해 출금할 수 없습니다!");
        }
        else{
        this.currentMoney=this.currentMoney-money;
        System.out.println(money+"만큼 출금되었습니다!");}
    };
    @Override
    public void checkMoney(){
        System.out.println("현재 은행에 남은 잔고는 "+this.currentMoney+"입니다!");
    };

}

그리고, Bank Interface를 implements 하여 제 주 거래 은행인 우리은행 클래스를 간단하게 만들어보았습니다. 정말 간단하지만, 그래도 현재 은행 보유금액이 0 이하일 경우 출금 할 수 없는 간단한 에러 핸들링을 넣어주었습니다.

package HardMisson;

public class BankUser {
    public static void main(String[] args) {
        WooriBank wooriBank=new WooriBank(0,"010-1234-5678","www.wooribank.com");
        //인스턴스 생성,힙에 할당되게 됩니당
        wooriBank.deposit(1000);
        wooriBank.checkMoney();
        wooriBank.withdraw(2000);// 에러 처리 발생~
    }
}

그리고 마지막으로 이런 은행 시스템을 사용하는 유저를 구현하며 심화과제를 완료헀습니다~

🐥 이런 점이 새로웠어요 / 어려웠어요

  • 사실 전공자이고, 이전의 자바 경험이 꽤 있어서 개념적인 부분에 자신이 있었는데, 오랜만에 자바를 쓰다보니 그래도 조금 가물가물한 개념들이 있었던 것 같아요!(특히 제네릭). 그 부분들에 대해서 본격적인 스프링 학습전에 큰 도움이 될 것 같습니다 :)

  • Java야 말로 객체지향 프로그래밍이라는게 가장 직접적으로 드러나는 언어라는 생각이 드는 과제였습니다 :)

  • 생각과제는 추후 아티클 정리후 올리겠습니다!

@hayounSong hayounSong self-assigned this Apr 7, 2023
@hayounSong hayounSong changed the title 1주차 [기본과제/심화과제] 1주차 자바 객체지향 개념/ 은행 구현하기 Apr 7, 2023
Copy link

@2zerozu 2zerozu left a comment

Choose a reason for hiding this comment

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

자바 문법 잘 보고 갑니다!!
좀 치시네요 ~~~

//인스턴스 생성,힙에 할당되게 됩니당
wooriBank.deposit(1000);
wooriBank.checkMoney();
wooriBank.withdraw(2000);// 에러 처리 발생~
Copy link

Choose a reason for hiding this comment

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

굿굿!!

Copy link
Member

@sojungpp sojungpp left a comment

Choose a reason for hiding this comment

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

수고하셨습니다 !! 코드랑 주석 엄청 깔끔해서 이해하기 넘 편했어요-!

Comment on lines +3 to +11
public interface Bank {
public abstract void deposit(int money);



public abstract void withdraw(int money);
public abstract void checkMoney();

}
Copy link
Member

Choose a reason for hiding this comment

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

옹 은행을 인터페이스로 만들기 이렇게도 활용할 수 있군여👏

Copy link

Choose a reason for hiding this comment

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

ㅇㅈㅇㅈ그생각은못함

Copy link

@GaHee99 GaHee99 left a comment

Choose a reason for hiding this comment

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

고생했슴둥!

Comment on lines +3 to +11
public interface Bank {
public abstract void deposit(int money);



public abstract void withdraw(int money);
public abstract void checkMoney();

}
Copy link

Choose a reason for hiding this comment

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

ㅇㅈㅇㅈ그생각은못함

@Override
public void withdraw(int money){
if(this.currentMoney-money<0){
System.out.println("잔고가 부족해 출금할 수 없습니다!");
Copy link

Choose a reason for hiding this comment

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

ㅋ실생활에서 없으면 100억부자 가능ㅇ인데

@yoonk2
Copy link

yoonk2 commented Jun 6, 2023

많이 배워갑니다 :) LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants