I'm basically coding an Insurance Database in Java using an Arraylist. What works so far is the adding, searching and deleting by index, saving and loading from a binary file. However im finding a great problem in searching through the arraylist by a variable.
However i have 2 classes : PrivateCarPolicy which holds the getters and setters and the toString() method and PrivateCarPolicyTable which holds all the methods for database control.
My code is about 1700 lines long so ill only post the revelant parts.
The toString() Method:
The Method to add Policies :
Note that im not including all methods or else this post will never end ;)
The Printing Method that displays the elements in the arraylist
AND LAST BUT NOT LEAST THE FAMOUS METHOD for searching by a variable which is not working :/
Joined: Jan 16, 2010
Sorry for this but i cant seem to find the edit button. Basically if someone can help me out with the searching it would be great dont hesitate to ask for some piece of code that is needed to solve this post.
I seriously hope that this is an exercise and not a real project. First I would refactor the class and create the classes Customer, Policy, Car. Read something about cohesion and OOP.
If you want to store a large number of objects in your Arraylist you should be thinking about using a real database because otherwise your performance will basically suck :P.
Why did you choose to use an ArrayList and not a LinkedList?
Variables should begin with a lowercase letter.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
There's no particular reason to use a LinkedList if you don't need bi-directional navigation, and if you need indexed access, I'd assume (without any testing) that an ArrayList would provide better performance.
In any case, whichever is used, the variable should be defined as a List (as opposed to the specific type), unless you need to enforce its ArrayList-ness.
But that's not the issue at this point, I suspect.