Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hello  RSS feed

 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • 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?

 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would help me help you if you posted a compilable piece of code.
Where are you creating a new 'Stats' object?
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Will always be zero because at the time this is executed 'wins' and 'draws' have been initialized to zero.

This is where setters and getters come in handy. Create a new method

to return the points at some point in time where wins/draws have legitimate values.
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Where does the magic number '5' come from. If it is the number of teams then it doesn't belong in the Stats class because Stats shouldn't have to know about the number of teams because there should be one Stats object per team.
 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Carey. I posted this twice accidentally yesterday. The code itself isn't complete.

There are six teams - they will play each other once so getting the average would be divided their total match points by 5 - the number of matches.

What I need to do is store user input via scanner in an array - user will first enter wins, draws, losses - I want to store this info in a matchStats array.
Then the user will enter via scanner points scored and types of scores - I want to store this info in a gamesStats array.

I need to loop through each of the six sides asking the same two questions and taking in the responses then outputting all the info in a league table.
So is my stats class unnecessary if I am saving all input into arrays?




 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
geronimo Finch wrote: . . .
There are six teams . . .
In which case you don't want / 5. You want / (TEAMS − 1)
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
geronimo Finch wrote:What I need to do is store user input via scanner in an array - user will first enter wins, draws, losses - I want to store this info in a matchStats array.
Then the user will enter via scanner points scored and types of scores - I want to store this info in a gamesStats array.

I need to loop through each of the six sides asking the same two questions and taking in the responses then outputting all the info in a league table.
So is my stats class unnecessary if I am saving all input into arrays?

First let me say that I'm not a sports person so I'm really vague on the relationships in your data. So far, based on the nouns you've been using, you probably need classes for: Team, Match, Game, and possibly MatchStats and GameStats. Teams play matches, matches are comprised of one or more games, a match is played between two teams, etc.. By breaking down the problem the objects you need and their relationships should emerge.

I don't see the need to explicitly need the win/draw/lose counts, couldn't you derive that from the match/game scores?

Using arrays is a bit brittle and I would suggest using Lists instead (e.g. ArrayList), for example an ArrayList<Team>.

You are putting your scanner input into arrays first, you haven't' shown it yet, but you'll need to take the values back out of the array and use them in the constructor. In this case, why put it into an array in the first place, put it directly into the constructor.

It might be helpful to see a mockup of the league table as you see it.
 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again, this is what the final should look like. Again, it will vary depending on the user input but the finished article should resemble something like this one.


 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok that table looks horrible! But it was aligned perfectly when I posted it?

 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ok, so let's say you just want simple tabular input, could do something like this. This approach, though simple, does not take into account the relationships between Teams, Matches, and Games, but seem to be more along the lines of where you were trying to head. You might want to start with this and add the other classes as you go along. This also requires a Stats class, which you have scratched the surface on but it will need to be flushed out. I also recommend putting the Stats class in its own Java file.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
geronimo Finch wrote:Ok that table looks horrible! But it was aligned perfectly when I posted it?

You put code tags round it and change where it says java to read text. And you should avoid tabs: use only spaces. Even then it is awkward because the widths of characters before and after are different.
 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood.

So, back to you on this one. I clarified with the instructor and turns out what I'm doing is complicating matters. Asking for wins, draws and losses on one scanner and then asking for tries, penalties, conversions and drop-goals on another scanner is too messy.

So, if I were to create 7 arrays - for wins, draws, losses, tries, penalties, conversions and drop goals. Then ask for how many wins did ****** have? How many draws did ****** have and so on. So that should make this a lot easier, right? *

In effect , Ireland should populate the first element of the array WINS, England populate the second element of the array WINS
Ireland should populate the first element the array DRAWS, England populate the second element of the ARRAY DRAWS and on and on


*he says hopefully.

 
geronimo Finch
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. I'm after confusing myself now. Okay until I get to this part and it just goes haywire:



So if I can sort out what to do above I just need to repeat that for six other blocks, draws, losses, tries, etc etc.


Also, this part was just for curiosity:

Full code so far:


 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
geronimo Finch wrote: . . . if I were to create 7 arrays . . .
Nononononononononono

That is horribly error‑prone. Create a Game class and Team class. Or at least a Team class with scores as its fields.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And beware of long lines. I have changed your post so you can see how to do it. Also only use // comments for short comments. For anything long use /* comments */
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!