-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotto.java
More file actions
158 lines (114 loc) · 3.11 KB
/
Lotto.java
File metadata and controls
158 lines (114 loc) · 3.11 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package first;
import java.util.Scanner;
import java.util.*;
class People{
int people_num;
Vector<Integer> people_lotto;
public People() {}
public People(int num) {
this.people_num = num;
people_lotto = new Vector<Integer>();
}
public void get_code() {
for(int i=0;i<6;i++)
this.people_lotto.add((int)(Math.random()*45+1));
}
void clean() {
this.people_lotto.clear();
}
}
class Player extends People{
public Player(int num) {
this.people_num = num;
people_lotto = new Vector<Integer>();
}
public void get_code(int[] a) {
for(int i=0;i<6;i++) {
this.people_lotto.add(a[i]);
}
}
}
public class ff {
public static void main(String[] args) {
// TODO Auto-generated method stub
Vector <Integer> Lotto= new Vector<Integer>(); //로또 생성
for(int i=0;i<7;i++)
Lotto.add((int)(Math.random()*45+1));
System.out.println("추첨자 수를 입력해주세요");
Scanner scan = new Scanner(System.in);
int people;
people = scan.nextInt();
int Money = 0;
int eMoney = 0;
People[] Peoples = new People[people]; //사람 생성, 사람마다 로또번호 생성
for(int i=0;i<people;i++) {
Peoples[i] = new People(i);
}
int num=1;
while(true) {
Money += people; //사람수 * 만원
System.out.println(" 1 - 로또 "+num+"회차 진행하기 2- 이월금액 확인하기 3 - 종료하기 ");
int select;
select = scan.nextInt();
int one=0;//1등
int two =0;
int three =0;
if(select == 1) {
Money = Money/2;//기부
int lucky = 0;
for(int i=0;i<people;i++) {
int o=0;
for(int w=0;w<6;w++) {
if(Peoples[i].people_lotto.contains(Lotto.get(w))==true)
o++;
}
if(o==6) {
System.out.println("호구"+i+"번 님이 1등에 당첨되셨습니다.");
lucky++;
one ++;}
if(o ==5) {
if(Peoples[i].people_lotto.contains(Lotto.get(6))==true) {
System.out.println("호구"+i+"번 님이 2등에 당첨되셨습니다.");
lucky++;
two++;}
else {
System.out.println("호구"+i+"번 님이 3등에 당첨되셨습니다.");
lucky++;
three++;}
}
}
System.out.println("당첨된 사람은 "+lucky +"명 입니다.");
int lucky_money = Money;
if(one>0) {
System.out.println("당첨금은 1등 "+one+"명은 각 " +(Money * 3/5 / one) + "만원");
lucky_money =(Money) * (3/5) / one;
}
if(two>0) {
System.out.println("당첨금은 2등"+two+ "명은 각 " +(Money /5 / two) + "만원");
lucky_money =(Money) /5 /two;
}
if(three>0) {
System.out.println("당첨금은 3등"+three+"명은 각 " +(Money /5/ three) + "만원");
lucky_money =(Money) /5 /three;
}
Money -= lucky_money;
System.out.println("로또금액의 50%는 기부되며, 당첨되지 않은 금액은 다음 회차로 이월됩니다.");
num++;
Lotto.clear();//초기화
for(int i=0;i<people;i++)
Peoples[i].clean();
for(int i=0;i<7;i++)
Lotto.add((int)(Math.random()*45+1));
Peoples = new People[people]; //사람 생성, 사람마다 로또번호 생성
for(int i=0;i<people;i++)
Peoples[i] = new People(i);
eMoney += Money;
}
if(select == 2) {
System.out.println("이월금액 : "+eMoney + "만원");
}
if(select == 3) {
System.out.println("종료합니다.");
break;}
}
}}