728x90
-LottoMain
1 2 3 4 5 6 7 | public class LottoMain { public static void main(String[] args) { MC mc = new MC(); mc.mentStart(); } } | cs |
-MC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import java.util.Arrays; public class MC { private int[] ball = new int[7]; public void mentStart() { System.out.println("로또 추첨을 시작합니다."); Machine machine = new Machine(); machine.start(); System.out.println("볼을 꺼냅니다."); for (int i = 0; i<=6; i++) { ball[i] = machine.getBall(); System.out.println(i+1 + "번째 볼은" + ball[i] + "번 입니다."); } System.out.println("오늘의 당첨 번호는 " + Arrays.toString(ball)); } } | cs |
-Machine
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Machine { private List<Ball> balls = new ArrayList<Ball>(); private int cnt = 0; public Machine() { for(int i = 1; i <= 45; i++) { Ball ball = new Ball(); ball.setNumber(i); balls.add(ball); } } public void start(){ Collections.shuffle(balls); } public int getBall() { return balls.get(cnt++).getNumber(); } } | cs |
-Ball
1 2 3 4 5 6 7 8 9 10 11 | public class Ball { private int number; public Ball(){} public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } } | cs |
반응형
'SKILL > JAVA' 카테고리의 다른 글
자바 IP관련 클래스 : InetAddress (0) | 2017.12.19 |
---|---|
자바 Vector연습예제 (0) | 2017.12.19 |
자바 로또 번호 생성 게임예제01 (0) | 2017.12.19 |
자바 달력출력 프로그램예제 (0) | 2017.12.19 |
자바 Calendar ( 출처 : http://huskdoll.tistory.com/566 , http://hyeonstorage.tistory.com/205) (0) | 2017.12.19 |