Created
September 5, 2021 02:57
-
-
Save wkdalsgh192/ffef8e26a0570a69efdc18b51f615560 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LottoTicket { | |
private static final int LOTTO_NUMBERS_SIZE = 6; | |
public LottoTicket(List<Long> lottoNumbers) { | |
List<Long> lottoNumbers = createNonDuplicateNumbers(); | |
validateSize(lottoNumbers); | |
validateDuplicate(lottoNumbers); | |
} | |
public void validateSize(List<Long> lottoNumbers) { | |
if (lottoNumbers.size() != LOTTO_NUMBERS_SIZE) { | |
throw new IllegalArgumentException("Only Six Numbers Allowed"); | |
} | |
} | |
private void validateDuplicate(List<Long> lottoNumbers) { | |
Set<Long> nonDuplicateNumbers = new HashSet<>(lottoNumbers); | |
if (nonDuplicateNumbers.size() != Lotto_NUMBERS_SIZE) { | |
throw new IllegalArgumentException("Numbers cannot be duplicate"); | |
} | |
} | |
} | |
public class LottoService { | |
private static final int LOTTO_NUMBERS_SIZE = 6; | |
public void createLottoNumber() { | |
LottoTicket lottoNumbers = new LottoTicket(createNonDuplicateNumbers()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment