aspose file tools*
The moose likes Beginning Java and the fly likes Methods and Arrays and Loops - Oh my! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Methods and Arrays and Loops - Oh my!" Watch "Methods and Arrays and Loops - Oh my!" New topic
Author

Methods and Arrays and Loops - Oh my!

Ernesto Gonzalez
Greenhorn

Joined: Apr 02, 2013
Posts: 2
Hello CodeRanch,

I'm a new java developer and a beginner - I have little to no experience with Java and could really use some help while I continue to search an answer for this question on this site. Basically me and a group of people want to hold a lottery - and we don't want anyone cheating so we've decided to have a code to act as our lottery. Basically there are 26 of us, so we've decided to assign each of us a letter. We want the Java program to randomly choose 10 letters from the 26 letter filled English alphabet and to place them into a string called "Players." After the 10 letters have been chosen and placed into this "Players" string, we will then choose 5 letters out of those 10 and place those in a string called "Losers." The remaining 5 letters will be the winners out of the 26 grouped lottery. So basically we want the program to choose 10 letters randomly from 26 - place it into a string called "Players" - randomly choose 5 letters from the "Players" string and print out the winners set which are the last remaining 5 letters that haven't been chosen for the losers string. We know what to do, but we don't know how to do it and this site seemed like the best place to ask for advice. We know we have to use arrays and more than one method, but we don't know how to do this. Any help is appreciated!

Just a quick rundown of how we want it to be printed out:

Players set: X A C F I K E L D P

Losers set: C I K E D

Winners set: X A F L P

Thank you in advanced!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hi, and welcome to the Ranch!

There's a lot of great help available here, but you have to do your part to. You'll be expected to ShowSomeEffort(←click) and DoYourOwnHomework(←click).

So what have you tried and what in particular are you stuck on?
Ernesto Gonzalez
Greenhorn

Joined: Apr 02, 2013
Posts: 2
Thanks for the warm introduction!

This is my code so far:



I know I should be using arrays, but I don't really know how. Any tips?

Thanks!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7801
    
  21

Ernesto Gonzalez wrote:Any help is appreciated!

Right, well first off, when programming in any language, it's important to be accurate when describing requirements.

1. You said: "We want the Java program to randomly choose 10 letters from the 26 letter filled English alphabet".
OK, here's a set of 10 randomly selected letters: E,G,Y,A,J,R,G,W,L,M.
What's wrong with it?

2. How do you think you might correct the problem? (Tip: think about how you would select 10 random cards from a deck.)

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
mike karl
Greenhorn

Joined: Mar 21, 2013
Posts: 13
i started you off a little, you have to figure out how to not use the same letter more than once, i would use an arraylist but its possible with just an array, dont capitalize the first letter in your method, and use capitalization for your class

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7801
    
  21

mike karl wrote:i started you off a little, you have to figure out how to not use the same letter more than once, i would use an arraylist but its possible with just an array, dont capitalize the first letter in your method, and use capitalization for your class

Mike,

All good advice, but if you are suggesting a change to somebody's code, just provide the change (and actually, even better, point them in the right direction to change their own code, rather than supplying them with "solutions").

I read your post as a complete solution and was just about to delete it (we don't like that sort of stuff here).

Winston
mike karl
Greenhorn

Joined: Mar 21, 2013
Posts: 13
Winston Gutkowski wrote:
mike karl wrote:i started you off a little, you have to figure out how to not use the same letter more than once, i would use an arraylist but its possible with just an array, dont capitalize the first letter in your method, and use capitalization for your class

Mike,

All good advice, but if you are suggesting a change to somebody's code, just provide the change (and actually, even better, point them in the right direction to change their own code, rather than supplying them with "solutions").

I read your post as a complete solution and was just about to delete it (we don't like that sort of stuff here).

Winston


im sorry i just wanted to provide a starting template, i will keep that in mind next time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Methods and Arrays and Loops - Oh my!