COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

ArrayList ArrayListProcessing.java NameSearching.java Hardware Store Program With ArrayList MyArrayList Program
MyArrayList.java
MyArrayListClient.java




NameSearching Program


Description

There are a list of names stored in an external data file.

This program reads the names from the data file and use an ArrayList of String to store them.

Then the program proceeds to use several methods to print the ArrayList and search a particular name.

Select the data file

Read the name to fill in the ArrayList

Print the ArrayList

Search a particular name in the ArrayList

Associated Concepts:

ArrayList


Algorithm:

main method:

Create an ArrayList of String

Select the data file use JFileChooser object

Call methods to:

Read names in the data file to populate the ArrayList

Print the ArrayList

Search a particular name

Print the result

readData method definition:

while loop: as long as the data file has data item

Read the next name and add it to the ArrayList

search method definition:

For each name in the ArrayList

If the name is equal to the searched name

    Found it and return true

If the loop ended without returning true

    Not found and return false


Boy Names Data File

Girl Names Data File

Source Code



Sample Run



Video