Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help with understanding instructions

 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
4.Date
5.Description - up to 20 lines of 30 characters
6.Provider SSN (Doctor's SSN)
7.Provider Name
8.Amount
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
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where would I call the get and set method from?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic