Bookmark Topic Watch Topic
  • New Topic

Storing multiple user inputs in an array  RSS feed

 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi there.

I need to generate a league table in Java based on results provided in the shape of user input. I have the 6 teams in an array. I need to ask the user how many wins, draws, losses each team has had.


How do I pull 3 separate values from the user and then store each value in a separate element of each array? so if one team wins 3, draws 2 and loses 1 - I need to put 3 into the wins array, 2 into the draws array and 1 into the losses array? I then need to total all this in a table.





 
Jain Pratik
Greenhorn
Posts: 14
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hey, i suggest you to create class 'Team' having three int variables to store win,loss and draw number. Then in main class create an Array of Type Team with size 6 and store the required information in each object.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Try using Scanner.
 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Okay. Thanks so far. This is my code so far. Not at this long, as you can probably tell. What I need to do is ask the user for wins, draws, losses then ask for types of scores during a tournament. I need to score the user input for all six teams in arrays. Am I going about this the wrong way?


 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Well, that code doesn't compile, so there is one problem.

But from looking at the code, I see you're creating a new scanner for each prompt. You don't have to do that. Just use the same scanner every time.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am afraid I can see serious problems with your design.
you should move as much code as possible (i.e. about 99% of it) out of the main method and into other methods, possibly in other classes.
Why have you not got a Team class? And why isn't there a Game class, which can have scores as its fields?
Do you play 15 games or 30 in the 6 Nations? If France play England once, you get 15; If France play England once at home and once away against England, then you get 30. That determines what sort of loop you want to use.

Your code lines are too long; I have gone back and corrected that (and a minor error with code tags), so you can see the right way to do that.
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
We have two threads discussing this problem at the same time, pick one and let the other one die.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Report post to moderator
There are more answers in the other thread so I'm locking this one.

Please direct all answers to http://www.coderanch.com/t/646701
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!