Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im trying to write this program to make three dice roll, Im pretty stuck and need some help please. public class DUNGEONSANDDRAGONS { private int

Im trying to write this program to make three dice roll, Im pretty stuck and need some help please.

public class DUNGEONSANDDRAGONS { private int fourSidedDie; private int sixSidedDie; private int twentySidedDie; public DUNGEONSANDDRAGONS (int fourSidedDie, int sixSidedDie, int twentySidedDie) { this.fourSidedDie = fourSidedDie; this.sixSidedDie = sixSidedDie; this.twentySidedDie = twentySidedDie; }

public int getFourSidedDie() { fourSidedDie = 4; return fourSidedDie; }

public void setFourSidedDie(int fourSidedDie) { this.fourSidedDie = fourSidedDie; }

public int getSixSidedDie() { return sixSidedDie; }

public void setSixSidedDie(int sixSidedDie) { this.sixSidedDie = sixSidedDie; }

public int getTwentySidedDie() { return twentySidedDie; }

public void setTwentySidedDie(int twentySidedDie) { this.twentySidedDie = twentySidedDie; }

@Override public String toString() { return "You have rolled " + fourSidedDie " on your d4, " + sixSidedDie + " on your d6, and " + twentySidedDie + " on your d20."; } }

import java.util.Random;

/* * This program is for use in Dungeons and Dragons to roll dice */ public class Dice {

public static void main(String[] args) { //creates the random Random random = new Random(); Dice fourDie = new Dice(); Dice sixDie = new Dice(); Dice twentyDie = new Dice(); /* *creates the integer named sixSidedDie *starts the random number generation at 1 and end at 6 *the plus 1 starts the random numbers at 1 and not 0 *as 0 isn't a option *this is for a six sided die */ int sixSidedDie = random.nextInt(6)+1; /* *creates the integer named fourSidedDie *starts the random number generation at 1 and end at 4 *the plus 1 starts the random numbers at 1 and not 0 *as 0 isn't a option *this is for a four sided die */ int fourSidedDie = random.nextInt(4)+1; /* *creates the integer named twentySidedDie *starts the random number generation at 1 and end at 20 *the plus 1 starts the random numbers at 1 and not 0 *as 0 isn't a option *this is for a twenty sided die */ int twentySidedDie = random.nextInt(20)+1; //showing the results to the user System.out.println("Rolling your dice."); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions