Keith R Wegner

Greenhorn
+ Follow
since Mar 17, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Keith R Wegner

K. Tsang wrote:Based on your current approach, Ankit is right - your Game class can be public. In fact Team and Game are 2 different things so why not Game public.

Now if Game is public there shouldn't be any problem because you are not trying to access some inner class thing.

I also noticed your Game class is immutable (eg not set methods). Nice.



Thanks to both of you.

I was up pretty late trying to code this and was probably suffering from sleep deprivation more than anything. I've made the appropriate changes and am moving forward nicely.

Thanks for the feedback.
15 years ago
Yes, he must be in a different section of this course

Jhakda Velu wrote:Hi
I won't give you the complete solution,but would give you a few pointers.
Use order by clause in your sql(say on home team) to get teams in a particular order.
While iterating through your resultset create a new instance of your Team VO if the previous team_name and the current is not the same(this is the reason for order by) .You will also need 2 variables to count number of wins and losses. This should be reset to 0 every time a new team is encountered.

You can have a Arraylist for opponents,keeping in mind that data will repeat every 4 elements(opponent_name,location, for,against).

Each Team VO should then be added to a collection which should be used to form the XML.



So, my SQL query should be SELECT home_team, away_team, home_score, away_score FROM table ORDER BY home_team

Now, how am I to retrieve the teams that were only in the away_team column

Example:
15 years ago

Jhakda Velu wrote:Hi
Can you give the exact table structure,that way i can hint about the possible query to use.
The HashMap example in my previous post should show you the direction. Try making a hashmap and add key value pairs to it and test.



Column Data __Type

game_id_______Integer
home_team____String
away_team____String
home_score____Integer
away_score____Integer
game_note_____String

The goal of pulling the data will be to create the following XML document


I'm also not 100% sure what the Team class' data structure should look like as far as implementing the opponent data.

I'm guessing I should make an inner class Opponent
15 years ago

Jhakda Velu wrote:Hi
I would try to fetch only the required data by tweaking the SQL. This way, i need to hit the DB only once and i need not check for duplicates.
In case you wish to use the HashMap approach, the key will be a string(the team name fetched from DB) and value can be the Team object created while iterating through the second resultset,duplicate values will be rejected, but here, there is an overhead of extra iterations.


How would this only be hitting the SQL table once?

So I would then need to run select home_team, away_team, home_score_away_score from table from the table.

Could you show me the pseudocode that would use a HashMap to store the distinct teams fetched from the home_team and away_team columns?

Thanks..
15 years ago

Jhakda Velu wrote:
Think of other ways to do this and people here would help you come out with good solutions(managing through SQL itself, using a HashMap with "home_team" as key and Team object as value(assuming you need a Team object(containing other attributes that you may fetch from the Database) and not just team names),etc etc).

Jhakda


Could you show me pseudocode for this; I am not sure if I understand it.
15 years ago
Look at the actual sequence of code being called. Do this by setting a breakpoint at your constructor, running the debugger and using the Step Over walkthrough to trace each step of your code, which will also show you the values of your variables - you will see that no conversion actually occurs because the conversion methods are never used.
15 years ago

Campbell Ritchie wrote:Art Vandelay, welcome to JavaRanch



Thank you. I'll be lurking around the JDBC, Java in General and SCJP boards for the time being.
15 years ago

The answer for this question is "String Version" Please tell me why?



Hi - Java will look for the "most specific" method when determining which overloaded method it will call when running code.

When looking here, we have Object argument and a String argument in these methods' signatures.

Since String extends Object (as do all classes), we conclude the overloaded method containing String in the signature will be used in this code.
15 years ago