-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathAttemptNumber.java
More file actions
34 lines (29 loc) · 1 KB
/
AttemptNumber.java
File metadata and controls
34 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package domain;
public class AttemptNumber {
//시도할 횟수 1~100 사이
private static final String NOT_POSITIVE_INTEGER_MESSAGE = "[ERROR] 시도 횟수는 양의 정수여야 합니다.";
private static final String INVALID_NUMBER_MESSAGE = "[ERROR] 시도 횟수는 100회 이하여야 합니다.";
private int attemptNumber; //시도횟수
public AttemptNumber(final int attemptNumber){
validate(attemptNumber);
this.attemptNumber = attemptNumber;
}
//유효성 검사
private void validate(final int attemptNumber){
if(attemptNumber <= 0){
throw new IllegalArgumentException(NOT_POSITIVE_INTEGER_MESSAGE);
}
if(attemptNumber > 100){
throw new IllegalArgumentException(INVALID_NUMBER_MESSAGE);
}
}
public void decrease() {
attemptNumber--;
}
public boolean isRemain(){
return attemptNumber != 0;
}
public int getAttemptNumber(){
return attemptNumber;
}
}