forked from woowacourse-precourse/java-lotto-6
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathUserView.java
More file actions
78 lines (62 loc) · 2.69 KB
/
UserView.java
File metadata and controls
78 lines (62 loc) · 2.69 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package view;
import model.Lotto;
import java.util.List;
import camp.nextstep.edu.missionutils.Console;
//사용자 입력 출력 관련된 거
public class UserView {
//게임 시작 메세지를 출력한다
public void printStartMessage(){
System.out.println("구입금액을 입력해주세요.");
}
//사용자로부터 구입할 로또 개수를 입력받는다
public int getLottoQuantity(){
String input = Console.readLine();
return Integer.parseInt(input)/1000; //인트로 변환, 1000원에 1장
}
//생성된 로또 번호 리스트를 출력한다
public void printGeneratedLotto(List<Lotto>lottos){
int lottoQuantity= lottos.size();
System.out.println(lottoQuantity+"개를 구매했습니다.");
for(int i=0;i<lottos.size();i++){
//로또 한개로 풀기
Lotto lotto= lottos.get(i);
//로또한개의 번호들
List<Integer>numbers= lotto.getNumber();
//각 번호들 문자열로 변환하기
String string = "[";
for(int j=0;j<numbers.size();j++){
string += numbers.get(j);
if(j<numbers.size()-1 )
string += ", ";
}
string+="]";
System.out.println(string);
}
}
//당첨번호 입력 받을거임 문자열->숫자를..? 입력:1,2,3,4,5,6
public int[] getLotteryWinningNumber(){
System.out.println("당첨 번호를 입력해 주세요.");
String input = Console.readLine();
String[]stringNumbers = input.split(",");
int[]numbers =new int[stringNumbers.length];
for(int i=0;i<stringNumbers.length;i++){
numbers[i]= Integer.parseInt(stringNumbers[i]);
}
return numbers; //숫자 1 2 3 4 5 6
}
public int getBonusNumber(){
System.out.println("보너스 번호를 입력해 주세요.");
String input = Console.readLine();
return Integer.parseInt(input);
}
//게임의 최종 결과를 출력함
public void printResult(int []matchingResult,double profitRate){
System.out.println("당첨 통계\n----");
System.out.println("3개 일치 (5,000원) - "+matchingResult[4]+"개");
System.out.println("4개 일치 (50,000원) - "+matchingResult[3]+"개");
System.out.println("5개 일치 (1,500,000원) - "+matchingResult[2]+"개");
System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원) - "+matchingResult[1]+"개");
System.out.println("6개 일치 (2,000,000,000원) - "+matchingResult[0]+"개");
System.out.println("총 수익률은 "+profitRate+"%입니다.");
}
}