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] 기본 과제 & 도전 과제 #2

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

Conversation

jinchiim
Copy link
Collaborator

SERVER PR

1. 기본 과제
2. 심화 과제
3. 🐥이런 점이 새로웠어요/어려웠어요

🐕 과제 구현 명세

1. 기본 과제

  • 기본 과제는 abstract Method, generic, interface 3가지를 중점으로, 상속, 선언, 인스턴스를 그 안에서 써줬습니다.

예를 들어 다중상속이 특징인 인터페이스 같은 경우는

class Hamster implements Animal,Feed { // 인터페이스 다중 상속 가능
    public String talk = "쥑쥑";

    @Override                           // 인터페이스의 경우 모든 메서드를 무조건 호출
    public void talk() {
        System.out.println("햄스터는 " + this.talk);
    }

이런식으로 다중상속을 보여줄 수 있는 코드를 작성해보려고 했어요.

제네릭 같은 경우는 코드 컨벤션으로 정해져있는게 신기하기도 하고 왜 사용하는지가 궁금해서 많이 찾아봤고,

개인적으로 다양한 타입을 만들고 싶을 경우, 다양한 타입의 메서드를 여러개 만드는 것보다는 제네릭을 사용하는게

편하다...는 결론이 나왔습니다. 아니면 말해주세요 🤧

    public static void main(String[] args) {
        Test<String> StringGeneric = new Test<String>(); // 제네릭 인스턴스 타입을 다르게 생성
        Test<Integer> IntGeneric = new Test<Integer>();

        StringGeneric.set("어려운것 같아요");
        String str = StringGeneric.get(); // String 형식

        IntGeneric.set(20);
        int val = IntGeneric.get(); // Int 형식

        System.out.println("제네릭은 " + str);
        System.out.println("한 이정도..." + val);
    }

그래서 코드도 하나의 generic class 로부터 Type을 다르게 받는 식으로 작성해 봤습니다.

마지막으로 추상화 클래스와 메서드추상화 상속, Overriding, Overloading을 위주로 작성해보려고 했습니다.

    @Override
    public void hate(String food){
        System.out.println("으! 아차! 이 음식은" + food + "였네요." );
    }
    @Override

    public void count(int food){
        System.out.println("맛있는건줄 알고 " + food + "개나 먹었어요.");
...
...
        eggplant.hate("가지");
        eggplant.count(3); // 오버 로딩 같은 food 지만 다른 타입으로 동작
    }
    }

심화 과제

  • Bank.java
  • Service.java

2가지 파일로 나누어서 작성했습니다.
ServiceDB같은 느낌으로 만들려고 했고, Bank는 작동하는 Main 화면처럼 만들었습니다.

주석을 저 자체도 이해하고 작성하는데 꽤 걸려서 🍇포도🍇 마냥 주렁 주렁 달아놨지만 (거의 풍년)
의도나, 생각했던 바를 이곳에 적자면,

구현하고자 했던것

  • 계좌 생성(무조건 간지작살나게 랜덤일것.)
  • 입금 기능
  • 출금 기능
  • 비밀번호로 위 두가지를 실행하기 전 확인하기

은 이 정도 였던 것 같습니다.

import java.util.Scanner;
import java.util.Random;

구글링을 정말 많이 했는데, 키보드로 입력받는 Scanner은 무조건 쓰고 싶어서 import 해줬습니다.
계정도 Random으로 생성하기 위해 import 해줬습니다.

    public static void createAccount() {                                                // 계좌를 생성하는 메서드
        Random random = new Random();
        Scanner scanner = new Scanner((System.in));
        String accountNumber = (random.nextInt(90000) + 10000 ) + "-" + (random.nextInt(90000) + 10000 );   // 무작위 계좌
        System.out.println("계좌번호: " + accountNumber);                                 // 계좌는 임의로 생성 후 바로 사용자에게 보여줌.
        System.out.println("고객이름: ");                                                 // 나머지는 scanner을 통해 입력 받은 값 사용.
        String name = scanner.nextLine();
        System.out.println("비밀번호: ");
        String password = scanner.nextLine();
        int budget = 0;                                                                 // 입금이 되어있는 상태가 아니기 때문에 0으로 시작.
        System.out.println("금액: "+budget);

        accounts[index] = new Service(accountNumber, password, name, budget);
        index ++;                                                                       // 새로운 계좌가 생길때마다 index++

        System.out.println(accountNumber + "인 계좌 계설 완료!");

        }

이 부분이 계좌를 생성하는 createAccount() 부분이다.

처음에는 Service에서 새로운 함수를 만들어 받는 식으로 하려고 했는데, 이상하게 그렇게 하면 막혀서 해당 함수를 Bank 파일에서 사용할 수가 없었다. Service에서 Service(String name, String pass....) 이 리스트를 맹글어 주는 부분 때문에 그런것 같은데....

이부분은 코리조...분께서 아시는 분이 있다면 🥲조언 부탁드립니다ㅜ (10시간동안 이거 고집하다가 포기했어요^^..)


아무리 봐도 주석을 너무 많이 달아서 이 파일에서 설명할 부분이 사라진것 같아요..아

            int outMoney = money-budget;
            System.out.println("출금 금액이 잔고보다 커, 빠질 수 있는 금액만 빠졌습니다. 빠진 금액: "+ outMoney );
            budget = 0;

원래 출금을 하는 부분은 금액이 클시, 출금이 되지 않는것으로 하려고 했는데

사실 자바를 해보는게 처음이라 이것저것 도전해 보고 싶어서 괜히 건들이다가 빠진 금액을 보여주고 계좌는 0원이 되는

쪽으로 작성해봤습니다. 당연히 실제 은행은 안되겠지만.... Java 왕초보의 발악이라고 생각해주세요.



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

우선 기초 부분은 정보도 많았고, 예시 코드도 많아서 이해하기가 쉬웠던 것 같아요.

근데 자바를 처음 해봐서 그런지 은행을 구현할때가 굉장히...힘들었던 것 같습니다. 이런저런 방법을 시도해 보고 싶었는데...
여러 오류를 맞이 하고 가루가 되어 털렸습니다.

그래도 재미있었습니다. 많은 피드백 부탁드려요ㅜ 코드도 줄여보고 모두가 한번에 알아 볼 수 있도록 깨끗하게 만들어보고 싶었는데 그런 부분이 저는 아쉬운것 같습니다. 조언 환영. 매우.

[WEEK1] 기본 과제 & 도전 과제 제출

#1
Copy link

@unanchoi unanchoi left a comment

Choose a reason for hiding this comment

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

Java 실력도 좋으신 것 같고, 과제하느라 정말 고생하셨습니다!!

public class abstractMethod {
public static void main(String[] args) {
Eggplant eggplant = new Eggplant(); // 인스턴스
eggplant.eat("유진");

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋ 가지가 유진이를 먹는건가요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ가지한테 침식 당한....유진...

Copy link
Member

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ넘 귀염귀염 한데요 ~~

import java.util.Random;

public class Bank {
Scanner scanner = new Scanner((System.in)); // 값을 받아오고, 지정해주는 면에서 편해서 사용

Choose a reason for hiding this comment

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

p4;

() 하나 빠져도 될 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

수정 완료 했습니다 감사해요!! 이것이..... OB???

Comment on lines 11 to 12
for(int i=0; i<index; i++){
if(accounts[i].getAccountNumber().contentEquals(accountNumber)){ // 받은 계좌와, getAccountNumber()에서 가져온 계좌가 일치하는지 확인.

Choose a reason for hiding this comment

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

p4;

for문 쓸 때, index로 리스트의 각 원소를 불러오는 역할만 하고 있으니

for (Service account: accounts) {
  account.getAccountNumber().~ 
}

이렇게 써도 괜찮을 것 같아요!

}

public static void findAccount() {
Scanner scanner = new Scanner((System.in));

Choose a reason for hiding this comment

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

p5;

입출력 받는 것 까지 구현하시다니 대단해요!
표준 입력에는 BufferedReader class도 있으니 참고하시면 좋을 것 같습니다.

Copy link
Member

@jun02160 jun02160 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 +16 to +17
Test<String> StringGeneric = new Test<String>(); // 제네릭 인스턴스 타입을 다르게 생성
Test<Integer> IntGeneric = new Test<Integer>();
Copy link
Member

Choose a reason for hiding this comment

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

제네릭 테스트를 어떻게 해야 할지 고민했었는데 이렇게 해보는 것도 너무 좋은 방법인 것 같아요!!

public class abstractMethod {
public static void main(String[] args) {
Eggplant eggplant = new Eggplant(); // 인스턴스
eggplant.eat("유진");
Copy link
Member

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ넘 귀염귀염 한데요 ~~

@jinchiim jinchiim self-assigned this Apr 18, 2023

public void withdraw(int money) {
if (money > budget){ // 출금 금액이 현재 잔액보다 클 경우 출금 불가
int outMoney = money-budget;
Copy link
Member

Choose a reason for hiding this comment

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

p4: PR 내용에 이부분에 대한 언급이 있어서 봤는데 보통의 은행이라면 출금할 금액이 부족하면 그냥 돈을 못빼니까 만약 돈을 어떻게든 뺄 수 있게 구현하신다면 money가 budget보다 큰지 검사(지금 하신대로)한 후에 금액이 부족하다는 메세지와 현재 잔고를 보여준 후 다시 출금할 금액을 입력받도록 구현하셨으면 더 좋았을 것 같아요!! (지극히 개인적인 생각입니다,,,)
자바가 처음이시면 공부하실 내용이 정말 많으셨을텐데 과제하느라 고생 많으셨습니다 :-) 다음주도 파이팅이에요오

[fix] Bank 코드리뷰 반영 commit

#1
[fix] Service 코드리뷰 반영 commit

#1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔥심화 과제🔥 심화 과제 제출 🥳기본 과제🥳 기본 과제 제출
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants