BIG
실행동영상
File.1
package Lotto;
public class Lotto {
public static void main(String[] args) {
User user = new User();
user.makeNumber();
Com computer = new Com();
computer.makeNumber();
int lottoCnt = computer.checkLotto(user);
System.out.println("사용자 입력 숫자 : " + user.getNumber());
System.out.println("컴퓨터 생성 숫자 : " + computer.getNumber());
System.out.println("당첨 숫자 : " + lottoCnt);
}
}
File.2
package Lotto;
import java.util.*;
public class User {
private List<Integer> numbers;
public List<Integer> getNumber()
{
return this.numbers;
}
public void makeNumber(){
Scanner scanner = new Scanner(System.in);
try{
numbers = new ArrayList<Integer>();
Set<Integer> set = new HashSet<Integer>();
String number = "";
while (true)
{
System.out.println("1 에서 45 사이의 정수를 입력하시오." + "("+set.size()+"/6)");
number = scanner.next();
if(( Integer.valueOf(number) > 0 ) && ( Integer.valueOf(number) <46 ))
{
set.add(Integer.valueOf(number));
}
if( 6 == set.size())
{
System.out.println("6 개의 숫자를 입력하셨습니다.");
break;
};
}
numbers.addAll(set);
numbers.sort(Comparator.naturalOrder());
System.out.println();
} finally {
scanner.close();
}
}
}
File.3
package Lotto;
import java.util.*;
public class Com {
private List<Integer> numbers;
public List<Integer> getNumber(){
return this.numbers;
}
public void makeNumber(){
Scanner scanner = new Scanner(System.in);
try{
numbers = new ArrayList<Integer>();
Set<Integer> set = new HashSet<Integer>();
int number = 0;
while (true)
{
number = (int)(Math.random()*46) + 1;
if(( number > 0 ) && ( number <46 ))
{
set.add(Integer.valueOf(number));
}
if( 6 == set.size())
{
System.out.println("6 개의 숫자를 입력하셨습니다.");
break;
}
}
numbers.addAll(set);
numbers.sort(Comparator.naturalOrder());
System.out.println();
} finally {
scanner.close();
}
}
public int checkLotto(User user)
{
List<Integer> userNumber = user.getNumber();
int LottoCnt = 0;
for(Integer comNumber : this.numbers)
{
if( userNumber.contains(comNumber))
{
LottoCnt = LottoCnt + 1;
}
}
return LottoCnt;
}
}
LIST
'!!...JAVA > !!...JAVA' 카테고리의 다른 글
[java]_예제_java MariaDBConnectionSample (0) | 2022.12.22 |
---|---|
[java]_예제_httpRequest 샘플 (0) | 2022.12.22 |
[java]_예제_컬렉션_01_List (0) | 2022.05.24 |
[java]_예제_예외처리_01 (0) | 2022.05.19 |
[java]_예제_추상클래스 & 상속_02 (0) | 2022.05.17 |