This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes need help with understanding instructions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help with understanding instructions" Watch "need help with understanding instructions" New topic

need help with understanding instructions

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I am in a Java class in college. The teacher gave us instructions for a program that he wanted us to write. I wrote the program and it worked so I thought it was ok. I lost points for not doing it correctly but can get the points back by redoing it. The only problem with that is that I still don't understand what I need to do differently. Here is my program:

Here is what he said I did wrong:
Here is an extract of the project assignment:
Design a Java class that will hold the data for an individual transaction:
The transactions would have the following information:
1.Group Account Number - 10 digits numeric
2.Social Security Number
3.Name - up to 30 characters
5.Description - up to 20 lines of 30 characters
6.Provider SSN (Doctor's SSN)
7.Provider Name
transfer the information from the screen controls to an instance of the Java
transaction class, and write out the resulting object to a Java Object
Output Stream.
You wrote out a "Vector" with a really long String in it - you never created
a class with these 8 fields, or moved any data into this class (since you
did not write it)
Could you maybe give me an example of what he is wanting?
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

Design a Java class that will hold the data for an individual transaction

What the professor is looking for is a separate Java class that will hold the data. Something like:

Remember that good OO style requires your member fields to be private and that your class have public assessor methods (getGroupNumber() and setGroupNumber(...))
You would then populate instances of this class with the data from the screen.
Just as a style note, identifying the type of a variable in the variable name is strongly discouraged. Instead of vAccount you should use a name like accounts. (The fact that it is plural indicates that it is a collection of some sort....) This is discouraged because it makes your code more strongly coupled -- or more confusing. This is bacause my next point is...
The use of Vectors is strongly discouraged. Instead, use a java.util.List (usually a java.util.ArrayList). Lists are faster and generally better than Vectors. Now, if you change the Vector to java.util.List, but your variable name is still vAccount, you can see where the confusion can arise -- it is no longer a Vector, but the name indicates that it is. A name like accounts will suffice regardless of the collection type. (Admittedly, though, I tend to use names like accountList, but that is still more generic than vAccount).
Hope that this helps. If it just confused you more, let me know and I'll try to explain better

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
Thanks so much for your help. One more question...What would be the argument that the set method would take and what would the get methods return? This is what I have now but I don't know what to put in the brackets or parentheses.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

The basic form of getters/setters is:

Note that the getter and setter are public methods so they can be called from outside the class. This is a pattern you will use a lot!
[ September 23, 2003: Message edited by: Jeanne Boyarsky ]

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

To summarize, the getter should return the same type as the variable, and the setter should take as a parameter the same type of the variable.
And just to point out another nigh universal convention: the initial letter of variable should be lower-case -- grpAccountNumber instead of GrpAccountNumber. Nothing that will cause your program to fail, it's just something to make it easier for another Java programmer to read your work. Capitalized first letters are almost always reserved for class/interface names.
Just nit-pickn'
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
Where would I call the get and set method from?
I agree. Here's the link:
subject: need help with understanding instructions
It's not a secret anymore!