본문내용
s.score;
}
public void takeTurn(){
ArrayList list = new ArrayList();
int dice_value = 0;
boolean duplicate = false;
for(;;) {
Iterator i = list.iterator();
dice_value = dice.nextToss();
if(list.isEmpty() == true) {
System.out.print("\t\tYou first roll is ");
} else {
System.out.print("\t\tYou next roll is ");
}
while(i.hasNext()) {
int temp;
temp = ((Integer)i.next()).intValue();
if(temp == dice_value) {
duplicate = true;
}
}
if(duplicate == true) {
System.out.println(dice_value + " - A MATCH!");
break;
} else {
list.add(new Integer(dice_value));
System.out.print(dice_value + " \tRoll Again?(y/n): ");
if(rollAgain() == false) {
score += dice_value;
break;
}
}
}
}
}
Dice.java
import java.util.*;
public class Dice {
private Random random;
private Die die1;
private Die die2;
public Dice(Random random) {
die1 = new Die(random);
die2 = new Die(random);
}
public int nextToss() {
return die1.nextToss() + die2.nextToss();
}
}
Die.java
import java.util.*;
public class Die {
private Random random;
public Die(Random random) {
this.random = random;
}
public int nextToss() {
int random_value = 0;
while(random_value <= 0) {
random_value = random.nextInt() % 6;
}
return random_value + 1;
}
}
}
public void takeTurn(){
ArrayList list = new ArrayList();
int dice_value = 0;
boolean duplicate = false;
for(;;) {
Iterator i = list.iterator();
dice_value = dice.nextToss();
if(list.isEmpty() == true) {
System.out.print("\t\tYou first roll is ");
} else {
System.out.print("\t\tYou next roll is ");
}
while(i.hasNext()) {
int temp;
temp = ((Integer)i.next()).intValue();
if(temp == dice_value) {
duplicate = true;
}
}
if(duplicate == true) {
System.out.println(dice_value + " - A MATCH!");
break;
} else {
list.add(new Integer(dice_value));
System.out.print(dice_value + " \tRoll Again?(y/n): ");
if(rollAgain() == false) {
score += dice_value;
break;
}
}
}
}
}
Dice.java
import java.util.*;
public class Dice {
private Random random;
private Die die1;
private Die die2;
public Dice(Random random) {
die1 = new Die(random);
die2 = new Die(random);
}
public int nextToss() {
return die1.nextToss() + die2.nextToss();
}
}
Die.java
import java.util.*;
public class Die {
private Random random;
public Die(Random random) {
this.random = random;
}
public int nextToss() {
int random_value = 0;
while(random_value <= 0) {
random_value = random.nextInt() % 6;
}
return random_value + 1;
}
}
추천자료
[자료구조] BFS&DFS&BST
[자료구조] post&prefix
자바 자료구조 족보
(자료구조) 스택을 이용한 후위연산 소스
(자료구조) 단순 연결리스트를 이용한 삽입 & 삭제 & 검색 소스
(자료구조) 이중연결리스트를 이용한 삽입 & 삭제 & 검색 소스
(자료구조) 큐를 이용한 환상형 연결리스트 삽입 & 삭제 소스
[자료구조] 배열을 이용한 다항식의 덧셈 곱셈 연산
[자료구조, Algorithm] 외부정렬(External Sort) PPT version
[자료구조] 원형 덱
[자료구조] 그래프
[자료구조] 피보나치수열 - int 데이타 사이즈를 넘어가는 결과값 계산 프로그램
C언어 자료구조 Binary Search Tree (이진 탐색 트리)
C언어 자료구조 HashTable 해시테이블
소개글