Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Roll the Dice program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I'm writing an application that rolls two six-sided dice, displaying the results after each roll and asking the user if they would like to roll again. It is supposed to show Roll 1, Roll 2, Roll 3, etc, but I am having problems with it showing that based on my counter variable. I have 5 classes created. Below is what I have for code so far.



Not sure about this last one, but the program should have a class called Die that stores the data for each die. This is what I have so far and I'm lost on it.

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, and welcome to the Ranch!

Wha specific problem are you having? People will be better able to help you if you TellTheDetails(←click).

Also, that's a lot of code, and the vast majority of it is not related to your problem. It will be easier for people to help you (and easier for you to help yourself!) if you write a small program that only shows your problem and doesn't have anything not related to it. An SSCCE(←click).
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Cantara wrote:Not sure about this last one, but the program should have a class called Die that stores the data for each die. This is what I have so far and I'm lost on it...


Right, well I'm assuming your Die class is supposed to model a single die, so why would you have a 'sum' field?

Also, it would appear that you're using the 'd' field to hold the number of sides, so why not call it 'numberOfSides'? Giving things meaningful names is a very important part of good programming.

If it's the random number stuff you're stuck on, have a look at the Random class (java.util.Random (←click)).

Winston
 
lowercase baba
Posts: 13074
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are writing too much code at once. Before you ever write a single line of code, you should analyze the problem and come up with all the individual things you need it to do. For example, my first pass at this assignment would be:

1) Generate an integer in the range 1-6
2) compute the sum of two numbers
3) Display a result
4) keep track of the number of rolls
5) ask the user something
6) Get input from a user
7) validate input
8 loop around and do it all again (if needed)


I'd make sure I could do each of the above steps by them selves before trying to combine them. I'd make sure one worked before I considered starting the next.
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic