Make a Simple Program

This week we were challenged to do three assignments from the Assignment Bank. Two of the post are to relate to the theme, “What’s (y)our story?”. For my first assignment, I decided to do an assignment under the “Code Assignments”. This relates to the theme because I am minoring in computer science. I really enjoy coding, and I jumped on the opportunity to do a quick code to complete part of week 2. I had a hard time deciding what a simple 10-20 line code program I could make that would relate to the theme. After some thought, I decided to code a virtual 6 sided die. As a young kid, I enjoyed playing board games, with my siblings and friends, that often required a die. Often, the hardest part of starting the game was finding the die. With this code, all the player would have to do is compile the code to take their turn “rolling the die”. In this code, there are two die being rolled simultaneously. It will output what each die rolled and the total from the two dice. To check out this program, copy the code below and paste into the online compiler provided. Once the code is pasted, click “Execute” located on the tab above the code to the most left.

package com.company;
import java.util.Random;
public class DS106 {
public static void main(String[] args) {
Random numGenerator = new Random();
int number = numGenerator.nextInt(6) + 1;
if (number != 0) {
System.out.println("The first die is a " + number + ".");
}
int number2 = numGenerator.nextInt(6) + 1;
System.out.println("The second die is a " + number2 + ".");

int totalNumber = number + number2;
System.out.println("The total number from the dice is " + totalNumber + ".");
}
}

This program is written in Java using IntelliJ as an IDE.

A screenshot of running the code in an online Java compiler.

Enjoy using this virtual die for multiple purposes! Big thanks to Brandon F. for creating this assignment.