ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 주사위 던지기2
    코딩/java 2019. 3. 3. 15:38
    반응형

    package casino;

     

    public class Practice66B {

     

    public static void main(String[] args) {

    int i = 1;

    game.Dice dice1 = new game.Dice();

    game.Dice dice2 = new game.Dice();

     

    do

    {

    dice1.roll();

    dice2.roll();

     

    System.out.println(i + ": 첫번째 " + dice1.toString() + ", 두번째 " + dice2.toString());

     

    i++;

    } while (dice1.getValue() != dice2.getValue());

     

    System.out.println("게임이 종료되었습니다.");

     }

    }

     

     

     

     

    package casino;

    import game.Dice;

     

    public class Practice66C {

     

    public static void main(String[] args) {

    int i = 1;

    Dice dice1 = new Dice();

    Dice dice2 = new Dice();

     

    do

    {

    dice1.roll();

    dice2.roll();

     

    System.out.println(i + ": 첫번째 " + dice1.toString() + ", 두번째 " + dice2.toString());

     

    i++;

    } while (dice1.getValue() != dice2.getValue());

     

    System.out.println("게임이 종료되었습니다.");

    }

     

    }

     

     

    ---------------------------------------------------------------------------------------------------------------------------------------------------

     

     

    package game;

     

    import java.util.Random;

    public class Dice {

     Random rg = new Random();

     

    private int value;

     

    public void roll() {

    value = rg.nextInt(6) + 1;

     }

     

    public int getValue() {return value;};

    private void setValue(int value) {this.value = value;};

     

    public String toString() {

    return "주사위 = " + value;

     }

     

    public Dice() {

    setValue(0);

    }

    }

     

     

     

     

    package game;

     

    public class Practice66A {

     

    public static void main(String[] args) {

    int i = 1;

     

    Dice dice1 = new Dice();

    Dice dice2 = new Dice();

     

    do

    {

    dice1.roll();

    dice2.roll();

     

    System.out.println(i + ": 첫번째 " + dice1.toString() + ", 두번째 " + dice2.toString());

     

    i++;

    } while (dice1.getValue() != dice2.getValue());

     

    System.out.println("게임이 종료되었습니다.");

     }

    }

     

     

    결과:

     

    Practice66A

     

     

    Practice66B

     

     

    Practice66C

     

    반응형

    '코딩 > java' 카테고리의 다른 글

    음식 정보 출력(package)  (0) 2019.03.03
    음식 정보 출력  (0) 2019.03.03
    랜덤 주사위 (같은 수가 나올 때까지)  (0) 2019.03.03
    package 연습  (0) 2019.03.03
    상자 정보 (상속2)  (0) 2019.03.03
Designed by Tistory.