• Post Reply Bookmark Topic Watch Topic
  • New Topic

two dimensional (array or ArrayList) or data base?  RSS feed

 
Chuck Beauregard
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully I don't breach any rules asking this question, but I've been trying to learn Java, so I can write a golf scoring program for my golf clubs. The more I read the more confused I get on some of this stuff. So I thought if I explain my issue perhaps you would point me in the proper direction so I could focus on it.

The crux of a golf scoring program is data associated with a person who is a member of a team. The team may be one or more people. That team will have gross scores for each of the 18 holes and net score (gross less handicap). A team score could be made up of from 1 to n "gross" scores and/or 1 to n "net" scores per hole. Teams would typically be grouped into "flights" for competitions or say 16 teams each. An event could have from 20 to 200 golfers contesting on a single day. Maybe I'll look at multi-day event later, a lot later.

Okay, as an old school (very old school) programmer for which this would be a large table with reports. Not very elegant but effective.

As a person with no OO experience and after reading too many books, I'm totally confused on what to be aiming for and need some clarity. Should I work towards:

1. having a "person object" with all of the data associated with that person, including but not limited to the person's scores, team affiliation, handicap, gender, flight, sidepot entry etc..

2. or a table in the form of a data base with SQL queries.

3. or a spreadsheet type table in memory backed up in a db

I find moving data around in Java to be "a pain the keeps giving" so I'd like to focus on the most effective solution first.

Thank in advance for your input.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66305
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 and 2, not 1 or 2.

A database is the best way to persist the data. When working with in the program, objects with properties is best.

This is where ORM comes in as a convenient eay to map the DB tables to Java objects. But you could also just do JDBC queries and create the objects yourself.

And it doesn't sound like there's just a Person object either -- there's at least a Team object, and perhaps Flight, and Competition, and Score.
 
Chuck Beauregard
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'm assuming ORM means Object Role Modeling. I'm off to read about it. Thanks for the pointer.
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66305
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chuck Beauregard wrote:Okay, I'm assuming ORM means Object Role Modeling.

Close: Object Relational Mapping.

ORM supplies a framework for taking relational data -- the most common way to persist data to a database -- and transforming it into objects, and vice versa. Hibernate and iBatis are the best known ORM frameworks. JPA is the standard API.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chuck Beauregard wrote:Hopefully I don't breach any rules asking this question, but I've been trying to learn Java, so I can write a golf scoring program for my golf clubs. The more I read the more confused I get on some of this stuff.

Well, at the risk of confusing you some more, I'm going to disagree with my colleague Bear slightly here; not in what he's saying (which I entirely agree with), but in whether you need it at this stage.

What does your program need to do? Is it supposed to be something you carry around on your PDA, or is it simply a "match scorer" that you bash into your laptop in the bar afterwards? Is it a private scorekeeper, or a database that your club wants to to implement to keep "all club scores for all members/matches for all time"? Do you need to get stats off it? Or membership data? Or do you just want a record of your round?

All of these things will affect how sophisticated the solution needs to be; and if it's just a private match log, it might be easier just to keep the results in a text file (maybe by date).

As far as Java classes are concerned, I suspect you're going to have several to consider: Course, Player, Match, Hole, and possibly even Club (as in 'club used' - if you're interested in logging that information) are just some that spring to mind. And whatever you decide in terms of storage (or 'persistence'), I suggest very strongly that you keep it completely separate from the business of keeping (or logging) scores.

That is: First write a program that can log scores, and make sure it works; then worry about how you're going to save them.

HIH

Winston
 
Chuck Beauregard
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all for the suggestions.

In response to what it is I'm trying to get. I have a very large Excel version with macros and Userforms that works fine, but ..... I've been told I've exceeded the limits of the heap file (whatever that is) caused by the fact Excel is poor at garbage collection.... This causes random stuff to happen which is easily fixed by restarting but not something you want to tell a new user.

Anyway so I decided to learn something new (retired) and write it again. It was strongly suggested I use Java by a friend, or at least I thought he was a friend.

The program is not a smartphone app but is to be standalone web application. Initially it is meant to score a one day tournament. Tournaments typically have 180 golfers and all kinds of formats and side bets. There are several web based scoring program out there but it is the combination of "format" and wagers that would make it useful for our golf club and the poor sob that has to do the scoring.

After several books Java syntax is not as foreign, but I must say examples like: "Welcome welcome = new Welcome;" don't help the learning process at all.

I think I understand how to build all of the instances of Objects with the attributes that I need, I don't understand how to manipulate them. Like say I have 150 players and I want to separate the women. Surely I don't step thru the instances of People to find all the women, do I?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66305
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorting and selection is where a database excels. In raw SQL you'd do something like: select * from person where gender="FEMALE" order by lastName,firstName

Assuming that you had a person table with a gender column containing one of MALE or FEMALE (and the name columns). (Or something similar -- there's never just one way to do things.)

In Java, you'd use JDBC to execute the SQL select. You could then marshal the results into a list of Person objects with the properties set to the column values. (Or let an ORM framework do it for you.)

The thing is, especially in a web app, you never read all the data into memory at once. You just grab what you need to process the current request, then discard it.
 
Chuck Beauregard
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I do plan to look at iBatis and hibernate later in the week.

I'm sure I'll be back with questions.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66305
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're more interested in "getting 'er done" than learning standard JEE, you might want to consider the Play framework (I prefer version 1.2.x to version 2 for various reasons).

It makes developing web apps pretty easy (well, as easy as web apps get, which isn't very), and has the best JPA integration of any framework I've used (using Hibernate under the covers).

But they "rolled their own" rather than using Servlets and JSP. That might or might not matter to you.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!