Question: JAVA LANGUAGE This assignment will give you practice with line-based and token-based file processing, writing to a file, and String methods. Instructions You are going

JAVA LANGUAGE

This assignment will give you practice with line-based and token-based file processing, writing to a file, and String methods.

Instructions

You are going to write a program that will read the contents of a virtual address book and split it out into multiple files.

Address Book Entries

Each entry will correspond to a single contact and will contain these entries:

  • Name
  • Phone Number
  • Email
  • Address

The name is guaranteed to come first, but the other entries may appear in any order. You can trust that name, phone number, and email are each single-line entries, while address is a 3-line entry (following standard US formats). There may be extra newlines, tabs or spaces. Your program will use line-based file processing to access each line in the file, but will need to use token-based processing to figure out which type of information is being provided.

contacts.txt

The contents of all address book entries (one after the other) will be stored in a file called contacts.txt

Here is a sample contacts.txt that you can use for testing your program.

Storing the Data

You should read the file in from contacts.txt and store the information in multiple arrays--one each for

  • names
  • phone numbers
  • emails
  • addresses

These arrays must be local (passed via parameters) and not instance variables or objects. You will have a chance to redesign this project with objects later.

Because you do not know ahead of time how many contacts you will need to read in, you will make an assumption about how big to set the size of your arrays---this should be bigger than your test data. You will want to keep track of how many entries you actually read in, so you don't print parts of the array that haven't been initialized. One of my test inputs for grading this assignment will use a VERY VERY LARGE file as input. To get full style points, it should be really easy for me to change your program to have larger arrays.

You will probably want to store the data without the extra tabs and spaces that are included in the contacts.txt file---you need to trim away the whitespace, and you may not use string methods (like trim) to do this. You are also not allowed to use the string method contains() in this program.

Outputting the data to files

You should output the contents of your arrays to several files using PrintStream. Here are examples for the sample contacts.txt:

  • addresses.txt - contains name/address pairs
  • emails.txt - contains name/email pairs
  • phones.txt - contains name/phone pairs
  • formatted_contacts.txt - contains a re-formatted address book entry that will be easier to read in next time.

Program Development

  • You must break your program into a minimum of 4 methods, not including the main. Each method should accomplish a specific task and be appropriately named.
  • I recommend writing the program, focusing on reading the input into arrays first, then worry about output files and formatting. Worry about whitespace last.
  • You may not print to any file while reading data from the file. Read in the entire file, then start printing.
  • Forbidden fruit:
    • Objects and class variables (constants are okay)
    • whitespace-trimming string methods
    • string "contains" and "split" methods
    • string builders

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!