public class ValueReturningMethod
1: import java.util.Scanner;
3: /**
4: * A program that rolls some dice. The command to roll the die is in its own
5: * method.
6: *
7: * @author Mark Young (A00000000)
8: */
9: public class ValueReturningMethod {
11: public static void main(String[] args) {
12: // create variables
13: int d1, d2, dice;
15: // Introduce yourself
16: System.out.println("\n\n"
17: + "I'm just rollin' some dice!");
18: pause();
20: // roll dice
21: d1 = rollDie();
22: d2 = rollDie();
23: dice = d1 + d2;
25: // report the result
26: System.out.println("I got a " + d1 + " and a " + d2 + ".\n"
27: + "The total is " + dice + ".");
28: pause();
29: }
31: /**
32: * Simulate rolling a six-sided die.
33: *
34: * @return a random number in the range 1..6
35: */
36: private static int rollDie() {
37: return 1 + (int)(6 * Math.random());
38: }
40: /**
41: * Prompt the user and wait for them to press the enter key.
42: */
43: public static void pause() {
44: Scanner kbd = new Scanner(System.in);
46: System.out.println();
47: System.out.print("Press Enter...");
48: kbd.nextLine();
49: System.out.println();
50: }
52: }