Team PUL

Making A Game That Uses 3 Dice In Java.

Hello! Today we’re going to learn how to make a little game in Java. This game will ask you to choose a number from 1-6 and remember it. The program will throw 3 dice 5 times and count how many times the number you selected shows up. The computer will then choose a number and throw 3 dice 5 times. If your number shows up more times than the computer’s number, you win!

Here are some things to watch for in the video:

First, be aware that every code statement requires a semicolon at the end of the line. This may be annoying, but it is necessary for your code to work.

Second, the program uses java.util.Scanner. This is a module (pre-built code that can be used in other programs) that allows the use of a scanner. Scanners are primarily used to get user inputs. The program also uses java.util.Random. This module allows for the program to choose random numbers.

Third, Java uses data types when declaring variables. The word String is used to declare text, the word int is used to declare variables with an integer, the word double (or float) is used for decimals, and boolean is used for conditions (such as hasEaten = true).

Fourth, for loops are used in this program. For loops repeat a block of code a certain number of times. For loops will typically take a variable that will be used as its “counter”, the max the number can be, and how much the number needs to increase by. So for example, for(int i = 1, i < 4, i++) will run a block of code three times.

You can find additional tutorials to Java by visiting w3schools or Javatpoint.