Skip to content

request for code revision #9

@jane-arinova

Description

@jane-arinova

Hi could you plz take a look at my code, I tried to solve 'Roll the die game' exercise by myself. I would really appreciate your feedback on my beginner java journey with your course, ty.

package testAU.chapter4;

import java.util.Random;

public class RollTheDieGame {
public static void main(String args[]) {
int spaces = 20;
int totalSpaces = 0;
int leftSpaces;
int maxRolls = 5;

    System.out.println("Welcome to the game 'Roll the Die!!!' Let's begin...");

    for (int i = 0; i < maxRolls; i++) {

        Random random = new Random();
        int die = random.nextInt(6) + 1;

        totalSpaces = totalSpaces + die;
        leftSpaces = spaces - totalSpaces;
        System.out.println("Roll # " + (i + 1) + ": You've rolled a " + die + ". " +
                "You are now on space " + totalSpaces + " and have "
                + leftSpaces + " more to go.");

    }
    if (totalSpaces == 20) {
        System.out.println("Congrats you won the game!!!");

    } else {
        System.out.println("Oops you lost the game, try again!!!");
    }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions