Question: in java Description You have probably noticed that many pieces of software allow searches to be completed with partial data. For example, on your cell

in java

Description

You have probably noticed that many pieces of software allow searches to be completed with partial data. For example, on your cell phone you usually have to enter only a few characters of someones name to get a match. Were going to look at how this can be implemented in Java.

An interface for the program is shown below. This program uses email addresses, but the same principles apply when names are used.

Please choose from the following menu of choices:

1. Enter a new email address

2. Find an existing email address

3. Quit.

What is your choice?

1

Enter the email address

a@ou.edu

Please choose from the following menu of choices:

1. Enter a new email address

2. Find an existing email address

3. Quit.

What is your choice?

1

Enter the email address

ab@ou.edu

Please choose from the following menu of choices:

1. Enter a new email address

2. Find an existing email address

3. Quit.

What is your choice?

1

Enter the email address

a@ou.edu

That email address has already been inserted

Please choose from the following menu of choices:

1. Enter a new email address

2. Find an existing email address

3. Quit.

What is your choice?

1

Enter the email address

ac@ou.edu

Please choose from the following menu of choices:

1. Enter a new email address

2. Find an existing email address

3. Quit.

What is your choice?

2

Enter the partial address

a

1. a@ou.edu

2. ab@ou.edu

3. ac@ou.edu

Please choose from the following menu of choices:

1. Enter a new email address

2. Find an existing email address

3. Quit.

What is your choice?

2

Enter the partial address

ac

1. ac@ou.edu

Please choose from the following menu of choices:

1. Enter a new email address

2. Find an existing email address

3. Quit.

What is your choice?

3

This program uses an oversize array. In other words, you need to create an array that is too large, and keep track of the number of elements that are currently stored in the array. When the array is constructed, the number of elements stored should be zero. As elements are added to the array, this value will increase. You may assume that 100 elements is sufficient for the array, and this value should be stored in a constant so it can easily be changed later if needed.

Inserting Data

When you go to insert data in this array, you need to be sure that it isnt already there. This is best done using Arrays.binarySearch(). Remember that you must have the data in sorted order to use binary search.

The binarySearch method returns a non-negative value when the item is found. When the item is not found, it returns insertionPoint -1. This means that you can use the value returned by binarySearch to keep the data sorted.

Method Signatures

The signatures for the methods are shown below.

public static void search(String[] data, int size, String target)

This method searches for a partial match of target and prints out any element of data (from 0 to size-1) that starts with the same characters as target.

public static int menuChoice(Scanner keyboard)

This method prints out the menu, allows the user to enter a choice, and checks to see that this choice is one of the legal ones. If the choice is not legal, the user should be given a chance to enter it again. If it is legal, the computation should proceed.

public static int addNewEmail(String[] data, int size, String insertMe)

This method should add insertMe to the array data if the String value is not already in the array. The int that is returned is the size of the array after the insertion. This size could be the same as it was previously (for example, if insertMe is already in the array) or may be one larger.

The fourth method you use will be the main method.

Class Constants:

public class AutoCompletion

{

public static final int ADD = 1;

public static final int SEARCH = 2;

public static final int QUIT = 3;

}

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!