Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:35:14+00:00 2026-06-18T11:35:14+00:00

I am writing a program that rolls 2 dice and gives the user the

  • 0

I am writing a program that rolls 2 dice and gives the user the option to repeat the roll (continue y/n). Additionally the application needs to recognize when certain rolls are made like rolling a 7 or 2 (snake eyes) im not sure if that needs to go in the main method or have its own class, im lost! please help. below is what i have for the outline of what the application needs to be im not sure how to code it.

This is my first time writing my own classes to be used in a main method the layout is as follows:

public class DiceRollerApp
{
    public static void main(String[] args)
    {
    }// end main method
}// end App class

class Die
{
    public Die()
    {}           // default to six-sided die
    public Die(int sides)
    {}  // variable number of sides
    public void roll()
    {}     // randomly picks a face value
    public int getValue()
    {}  // returns the face value
}// end class Die

class PairOfDice
{
    public PairOfDice()
    {}          // default to six-sided dice
    public PairOfDice(int sides)
    {} // variable number of sides
    public void roll()
    {}         // roll both dice
    public int getValue1(){}       // get value of die1
    public int getValue2(){}       // get value of die2
    public int getSum()    {}
    // get sum of both dice
}// end class PairOfDice


public class Validator
{
    public static String getString(Scanner sc, String prompt)
    {
        System.out.print(prompt);
        String s = sc.next();  // read user entry
        sc.nextLine();  // discard any other data entered on the line
        return s;
    }

    public static int getInt(Scanner sc, String prompt)
    {
        int i = 0;
        boolean isValid = false;
        while (isValid == false)
        {
            System.out.print(prompt);
            if (sc.hasNextInt())
            {
                i = sc.nextInt();
                isValid = true;
            }
            else
            {
                System.out.println("Error! Invalid integer value. Try again.");
            }
            sc.nextLine();  // discard any other data entered on the line
        }
        return i;
    }

    public static int getInt(Scanner sc, String prompt,
    int min, int max)
    {
        int i = 0;
        boolean isValid = false;
        while (isValid == false)
        {
            i = getInt(sc, prompt);
            if (i <= min)
            System.out.println(
            "Error! Number must be greater than " + min + ".");
            else if (i >= max)
            System.out.println(
            "Error! Number must be less than " + max + ".");
            else
            isValid = true;
        }
        return i;
    }

    public static double getDouble(Scanner sc, String prompt)
    {
        double d = 0;
        boolean isValid = false;
        while (isValid == false)
        {
            System.out.print(prompt);
            if (sc.hasNextDouble())
            {
                d = sc.nextDouble();
                isValid = true;
            }
            else
            {
                System.out.println("Error! Invalid decimal value. Try again.");
            }
            sc.nextLine();  // discard any other data entered on the line
        }
        return d;
    }

    public static double getDouble(Scanner sc, String prompt,
    double min, double max)
    {
        double d = 0;
        boolean isValid = false;
        while (isValid == false)
        {
            d = getDouble(sc, prompt);
            if (d <= min)
            System.out.println(
            "Error! Number must be greater than " + min + ".");
            else if (d >= max)
            System.out.println(
            "Error! Number must be less than " + max + ".");
            else
            isValid = true;
        }
        return d;
    }
} // end class Validator

I have written the validator class already but did not post it here, its purpose is to simply validate the string from the question “Continue? y/n: “

im not sure how to code the die class and the pair of dice class, and i dont know if i need to have a separate class for the DiceRollerApp.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:35:16+00:00Added an answer on June 18, 2026 at 11:35 am
    class Die 
    {
        private int sides;
    
        private int value;
    
        public Die() {
            this.sides = 6;
        }           // default to six-sided die
    
        public Die(int sides) {
            this.sides = sides;
        }  // variable number of sides
    
        public void roll() {
            value = (int)(Math.random() * (sides-1)) + 1;
        }     // randomly picks a face value
    
        public int getValue() {
            return value;
        }  // returns the face value
    
    }// end class Die
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program that lets the user input 6 temperature readings, and then
I am writing a program that needs to read in very large files (about
I'm writing a program that allows a user to perform arithmetic operations with big
Im writing a program that needs to be able to find the difference between
I'm writing a program that relies on the user having third party packages already
I am writing a program that needs to do a bit of arithmetic. Here's
I am writing a program that takes in an input file from the user.
I'm writing a program that needs to get the install date and version information
I'm writing a program that needs to take input from an XBox 360 controller.
I'm writing a program that needs to watch for file system events on multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.