• Sat. Oct 1st, 2022

    Use Java to achieve the following dice games: drop the two dice, if the total value of the score is 7 points, win; otherwise, lose

    ByGoodBoy

    Sep 23, 2022
    3 thoughts on “Use Java to achieve the following dice games: drop the two dice, if the total value of the score is 7 points, win; otherwise, lose”
    1. Public class dice {
      private into;
      public dice () {
      value = (int) (math.random ()*6 1); Interaction
      }
      PUBLIC Int Get_value () {Return value;
      }

      Public static void main (string [] args) {
      n dice dicea = new dice ();
      dice diceb = new dice ();
      if (dicea.get_value () diceb.get_value () == 7)
      system.out.println ( "Win !!");
      else {
      system.out.println ("loss !!");
      }
      }
      }

    2. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------
      Public class dice {

      private int value;

      public into getValue () {
      Return this .value;
      }

      public void setvalue (int value) {
      if (value u003C= 0) {
      this.value = 0;
      Return;
      }
      this.value = value % 7;
      }

      public void next () {
      random r = new rate ();
      int i = 0;
      do {
      i = r.nextint ();

      } while (i == 0);
      }
      }

      ------------------------------------------------------------------------------------------------- -------------
      Public Static void main (string [] args) {

      dice dicea = new dice ();
      dice diceb = new = new Dice ();

      dicea.next ();
      diceb.next ();

      if (DICEA.GetValue () DICEB.GetValue () = = 7)
      system.out.println ("win !!");
      else {
      system.out.println ("loss !!");
      }

      }

    3. CLASS DIE {

      int () {

      return (int) (math.random ()*6 1);
      }

      }
      CLLSS DICEGAME {
      static int Die1, DIE2;
      boolean play () {
      return all1 die2 == 7? True: false: false: false: false: false: false: false: R n}
      Public class test {
      Public static void main (string [] args) {
      die d1 = new die (); r n dicegame dg = new dicegame ();
      dg.die1 = d1. ();
      dg.die2 = d2. ();
      if (dg.play ()) {
      system.out.println ("You win!");
      }
      else {
      system.out.println ("You lose!");
      }
      system.out.println (dg.die1 "" dg.die2);
      }
      }

    Leave a Reply