본문 바로가기

개발 이야기/CC-Java

[2주차] 로또게임 - Step2. 피드백

src/main/java/step2/InputView.java

  • InputView 등 상태가 없는 클래스의 경우 굳이 인스턴스를 생성하여 사용하는 것 보다 static으로 사용
    => 완료

src/main/java/step2/Lotto.java

  • 현재 Lotto의 클래스 내부에 존재하는 메서드는 모두 List (로또번호들) 와 관련된 일을 수행하고 있습니다. Lotto의 멤버변수로 List를 두어 구현해보면 어떨까요? 그렇게 된다면 로또 번호와 관련된 메서드들을 모을 수 있을 것 같아요 :)
    => 완료

  • 리턴타입으로 클래스가 아니라 인터페이스를 사용하는게 도움이 될 수 있습니다 :)
    => 완료

src/main/java/step2/LottoLottery.java

 public List lotteryStatics(Set<ArrayList> purchasedLottos, int\[\] winningNumbers) {  
        List resultMatching = new ArrayList<>();  
        for (ArrayList purchasedLotto : purchasedLottos) {  
            [resultMatching.add(matchWinningNumbers(purchasedLotto,](resultMatching.add(matchWinningNumbers(purchasedLotto,) winningNumbers));  
        }  
        return resultMatching;  
    }  

     private int matchWinningNumbers(ArrayList purchasedLotto, int\[\] winningNumbers) {  
  • stream이 항상 옳은것은 아니지만 아래의 코드를 참고해서 구현해볼 수 있을 것 같아요 :)

    return [Arrays.stream(winningNumbers)](Arrays.stream(winningNumbers))  
                  .filter(winningNumber -> purchasedLotto.contains(winningNumber))  
                  .count();  

    => 완료

    • static final int FIRST = 2000000000; 대신 static final int FIRST = 2_000_000_000;
      => 완료
  • 상금 타입을 Enum으로 관리 => 완료
  • 매직넘버로 구현된 부분 상수로 분리해보면 좋을 것 같아요~ => 완료
    // N개 일치하는 로또가 몇장인지 저장 (Map에 put)  
    private void completeStatistic(List resultMatching, int matchCount) {  
        int test = 0;  
        for (int matchingNumber : resultMatching) {  
            if (matchingNumber == matchCount) {  

프로그래밍 요구사항 중 아래와 같은 부분이 있습니다

indent(인덴트, 들여쓰기) depth를 2를 넘지 않도록 구현한다. 1까지만 허용한다.
예를 들어 while문 안에 if문이 있으면 들여쓰기는 2이다.
힌트: indent(인덴트, 들여쓰기) depth를 줄이는 좋은 방법은 함수(또는 메소드)를 분리하면 된다.

참고해서 구현해보면 좋을 것 같아요! => 완료

  • LottoLottery와 관련된 로직에 대한 단위 테스트