An address database, Winter 2016
Consider executing java -jar address.zip
:
Current person records: 0: Frank Bone, email: bone@re.org, phone: 885-11-87 1: Julius Caesar, email: -, phone: - 2: Clive Freemantle, email: freemantle@spam.org, phone: 112-22 33 12 3: Eve Gardener, email: -, phone: 32-44-2234 -------------------------------------- Main options: 0: Browse person entries ❶ 1: Toggle filtering person entries ❷ 2: Create new person entry ❸ 3: Delete person entry ❹ 4: Exit Your choice: 2
List all person records within your database. In presence of a filter (See ❷) only a subset of entries will be displayed. |
|
For large person databases listing all entries becomes cumbersome. You may want to define filters limiting your visible result output by examining the last name attribute. Java™ allows for matching strings by regular expressions to be used with e.g. String.matches(...). Examples:
|
|
Creating a new person record |
|
Deleting a person record from your database |
In order for entries to survive program termination we need a
persistence
mechanism. The example application will create a new file
address.txt
on first invocation when adding at
least one person:
Frank,Bone, ,885-11-87 Julius,Caesar, , Ee,Ff,hh,45 A,B, ,24 Eve,Gardener, ,32-44-2234
Each person record is being represented by four values being separated by three commas. Empty attribute values require a single space. The method String.split(...) is your friend when reading this file on program startup using “,” as separator split token.
The following resources may help you getting started with Java™ file input/output: