Jump to content

Java Help!

Hey guys! Ok so I have to do this lab for my Intro to Computer Science class, but I don't understand it......like at all. It's partially because I was surfing the internet during class trying to find components for the computer I'm going to build. Yay! It's my first one so I'm pretty excited. Anyway, I was curious if someone could help me with the class in the lab that involves generating the random number. I know that there is a build in class in Java that generates random numbers for you, but I'm not really sure if that is what is necessary in this situation. I really appreciate your help! Oh and I can't quote people's replies because I use Internet Explorer (I know.....) so if you think that you could help me, I would appreciate if you guys would follow the post. Thanks again!!!!

post-162792-0-05872300-1416625519_thumb.

Link to comment
Share on other sites

Link to post
Share on other sites

Oh great! Thanks a lot, I've actually been looking for someone on Youtube who does an entire Java tutorial. Thanks so much!

Link to comment
Share on other sites

Link to post
Share on other sites

We're here to help with problems, not to write code for you. Post code so we know what you have done and ask more specific questions. If you don't have anything started, then break the problem down into it's requirements and do what you can first.

Link to comment
Share on other sites

Link to post
Share on other sites

I wasn't asking you guys to write the code for me, I was asking for some explanation of how to write it. I got help though so I don't know why you needed to post anything.

Link to comment
Share on other sites

Link to post
Share on other sites

I wasn't asking you guys to write the code for me, I was asking for some explanation of how to write it. I got help though so I don't know why you needed to post anything.

I'm not trying to be mean but this is kind of how your question read

 

"I have an assignment to do but don't know how to do it because I didn't pay attention in class. I haven't even tried to do anything so far but help me do this major component of the assignment. I know about this library that could help but because I haven't tried to use it, I don't know if it's what I need."

 

Showing your code can show us that you've actually tried and aren't just getting us to do your homework (people do that). It also gives us an idea of what you know and don't know. And we can see where the assignment is going right/wrong.

 

Anyway, if you have any issues while doing your assignment then feel free to post. I or someone else will help. However if the tutorials was all you needed to do it, then great. Good luck :)

Link to comment
Share on other sites

Link to post
Share on other sites

I don't understand what he means by an instance variable that generates random numbers. Wouldn't you just use a method for that? I don't really understand that.

 

 

 

 

Update: Oh wait...I think I figured it out! haha I'll repost later for you guys to check!

Link to comment
Share on other sites

Link to post
Share on other sites

There are many ways to tackle this.

 

One OOP way is to create a class called Die, which defines how many sides it has. It will define a Roll method, which in turn uses a Random number generator (this is delivered by the programming language) to return a result. Maybe even make a Roll overload which rolls the die N times and returns a collection of results.

 

Then you can make whatever small script or console app to take input from the user of how many dice they want to roll and how many sides each die should have. From the problem I see they use the XdY, where X is how many dice and Y is how many sides they have. You should be able to parse that pretty easily, just searching for the index of d in the input and naively treat everything before as a number and everthing after as a number. You could catch exceptions if the conversion from string to int goes wrong, and tell the user to fix that.

 

Don't worry about structure to begin with, don't overthink it. Just get started coding, this is a super simple app, not much can go wrong.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×