• Post Reply Bookmark Topic Watch Topic
  • New Topic

Someone tell me where im going array (wrong)  RSS feed

 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


output is:
How many tickets would you like?
5

Ticket 1: 1 30 38 39 45 14
Ticket 2: 35 3 42 18 40 2
Ticket 3: 27 7 19 40 25 35
Ticket 4: 34 17 0 4 38 33
Ticket 5: 14 6 5 46 48 1

The following is my requirements:
•Each row is called a "play." The plays are lettered A, B, C, etc.
•There are always an even number of plays on a ticket. (Lotto tickets cost $1 for two plays)
•Each play has the following characteristics
•There are 6 randomly selected integers
•The integers are from 1 through 44
•Integers may not be repeated
•Integers are sorted from smallest to largest on each line
•Integers are always shown as 2 digits. If the number is less than 10, a leading zero is printed.
•There are a maximum of 10 plays per ticket. (A - J)

Your program should begin by asking the user to enter an even number of plays. The program should do "input validation" and not let the program continue until the user enters an even number. The minimum requirement for this program only requires you to pick numbers up to 10.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you mean "awry". It looks like you've made a good start. Your next job might be to get multiple plays per ticket. Don't worry about labeling them at first (A-J) ... just be able to prompt for the number of plays per ticket, verify that it's an even number from 2 to 10 and then print out that number of rows. The next job after that would be sorting the numbers so that they increase from left to right.
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't like to see so much code in the main method. In my opinion, it should contain one statement. Lots of people will happily write longer main methods, but I can find few people who will write main methods with fewer statements than I suggested
It would be more object‑oriented to create your Lotto class, give it a constructor, fields, etc, and a method which starts off the game. Your main method reduces to this:-You are using one statement to create an object and use its reference once and once only. After that, everything else happens in the Lotto object and you never need that reference again. (If you get desperate, you can retrieve it easily inside the Lotto object by writing this.)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I don't like to see so much code in the main method...

@mike: I wholeheartedly agree with Campbell (which is rare enough in itself to deserve your attention ). And if you're interested in a couple of methodologies similar to the one he describes, have a look at the MainIsAPain page.

Another thing that might help is a word analysis of your requirements. It's by no means comprehensive, but it's often a good place to start, and it's very simple.
1. Go through your requirements and pick out all the verbs and nouns and make lists of them.
2. The nouns will usually point you to classes that you'll need (or fields in those classes).
3. The verbs will point you to methods that you're likely to need.

Like I say, it's very crude, but it can sometimes help if you're overwhelmed by "trying to think about everything at once" because it's simple, focused, and non-programmatic (ie, it's exercising a different part of your brain). It may also help you to break up some of that monolithic code that right now is all in your main() method.

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . .
@mike: I wholeheartedly agree with Campbell (which is rare enough in itself to deserve your attention ). . . .
Nobody else ever agrees with me

Actually that ain't true. I find I agree with Winston all the time.

Another thing I would recommend is to divide your task into small pieces. Get one piece working until you are sure it works correctly and the move on to the next piece. You may decide I am telling you the same as Winston has just said, only differently. And that main is a pain link is good.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!