Scott Grissom
School of Computing & Info Systems
Grand Valley State University
picture

Project 3: Fake Names Analyzer

Preparation

Do the following before starting this project:

  • Read chapter 4
  • In particular, read and understand the Web Log Analyzer project introduced in section 4.12
  • Due at the start of lab

Objectives

After completing this project, you should be able to:

  • use ArrayLists to maintain and process collections of objects
  • use for-each loops
  • use while loops
  • read data from external text files
  • use String methods to manipulate data

Project Specification

Implement classes that allow a text file of movie data to be read and queried.

Getting Started

We are providing a BlueJ project to get you started.

  1. Connect to the CSIS R: drive
  2. Start Blue J and open the FakeNameAnalyzer project located on the R: drive in the CS 162 folder
  3. Save this project to your N: drive
  4. You will modify the existing FakeNameEntry and FakeNameAnalyzer classes and may ignore the GUI class for now.
Fake Name Entry

Implement a class to maintain information about a fake name entry including: gender (boolean), first, last, month (int), day (int), year (int), address, city, ST, zipcode, credit card, balance (double).

  • Finish the class "FakeNameEntry" that is started for you .
  • Provide appropriate names and data types for each of the instance variables.
  • public FakeNameEntry (String info) - a constructor that initializes all of the instance variables to appropriate values. Parse the provided String to extract each data element. Refer to the information below on how to parse a String into various parts. Trim any extra blank spaces before and after each field. Here is a sample line of data:
    female, Grace, Matney, 4/9/1960, 1154 Yorkshire Circle, Greenville , NC, 27834, Visa, 15339.19 
  • provide get methods for each instance variable
  • public String toString( ) - return a formatted String containing the mailing address. For example,
    John Smith
123 Elm St.
Anytown, ST 12345

Be sure to test this class thoroughly before moving on to the Analyzer class.

Analyzer
  • Finish the class "FakeNameAnalyzer" that is started for you.
  • Provide appropriate names and data types for any required instance variables. Actually, you only need one.
  • public FakeNameAnalyzer ( ) - a constructor that instantiates instance variables as needed.
  • public void readData(String filename) - open the provided filename and read all data. There are 10,000 entries! A data file is included in the FakeNameAnalyzer folder ("FakeNames.txt") that you can not see from within BlueJ. You can see it from within the Windows Explorer though. Refer to your class notes for information about opening and reading a text file using the Scanner class (read this brief Scanner tutorial).
  • public int countNames ( ) - return the number of names in the database. This method only needs to contain one line of code!
  • public FakeNameEntry getHighestDebt ( ) - return the person with the highest credit card balance.
  • public FakeNameEntry getYoungestCardholder ( ) - return the youngest person in the database. Give careful thought to this one!
  • public String getCardSummary(String card) - return a String that summarizes total cards and average debt for the requested card. Valid entries are: Discover, Visa and MasterCard. Use the DecimalFormat class to help format the dollars and cents ouput. Sample result should look like the following.
    Discover: 4000 cards with average balance of $4,023.63  
  • public int countDebtFree ( ) - return the number of cardholders with no debt.
  • public ArrayList <FakeNameEntry> getMailingList(double low, double high) - return an ArrayList of all cardholders who have a balance between low and high (inclusive).
  • public ArrayList <FakeNameEntry> getMailingList(String keyword) - return an ArrayList of all cardholders that have a city or state that contains the provided keyword (ignore case). For example, keyword of "IN" would return all cardholders in Indiana as well as any cities that contain "in".
Parsing Strings

The String, Integer and Double classes provides a number of useful methods to help extract information from a String

  • The String trim() method removes blank spaces at the start and end of a String
  • The String split(":") method returns an array of sub-strings separated by the provided delimiter. For example, "HH:MM:SS" would be separated into three words: {"HH", "MM", "SS"}
  • Integer.parseInt("123") is passed a String and returns an integer.
  • Double.parseDouble("123.45") is passed a String and returns a double.

For example, given a String that starts with a blank space and ends with a blank space, the following code will extract a name and an age.

  1. String info = " Justin:20 ";
  2. info = info.trim();
  3. String [ ] tokens = info.split(":");
  4. String name = tokens[0];
  5. int age = Integer.parseInt(tokens[1]);

Sometimes, it is useful to split a String using more than one delimiter. Use a vertical bar | to separate the multiple symbols in the split method. For example, given a String that starts with a blank space and ends with a blank space, the following code will extract a name and an age.

  1. String info = " Justin:20/Smith ";
  2. info = info.trim();
  3. String [ ] tokens = info.split(":|/");
  4. String first = tokens[0];
  5. int age = Integer.parseInt(tokens[1]);
  6. String last = tokens[2];
Creating a Graphical User Interface

You can use the GUI to test your work as it evolves.

  • Change the title that appears in the GUI window to include your name. You will need to read through the GUI code to determine what change to make.
  • Use the File--Open method to access the "FakeNames.txt" file once you have written the read method in the Analyzer class.
  • One of the first lines in the GUI constructor attempts to open the file but it is currently commented out. You might choose to uncomment it during development so that you do not have to acess the File->Open menu every time. Remember to remove the line of code when you are finished with the project.
Bonus Challenges

If you finish the project early, you may want to attempt this additional challenge.

  • Modify the GUI so that warnings pop up for the following errors: 1) no filename was specified, 2) textfields are blank for either the keyword or the high and low values. Use JOptionPanes for the pop-up messages. (3 pts)

Sample Results

The following displays as partial results from searching for "jackson".

Liana Woodard
2195 Washington Avenue
Jackson, MS  39211
Clyde Hansen
2131 Cherry Tree Drive
Jacksonville, FL  32207
Lillian Walker
4116 Maple Avenue
Jackson, CA  95642
95 names listed

Grading Criteria

This project is worth a possible 100 points.

  • Stapled cover page with your name and signed pledge (- 10 pts if missing)
  • The code compiles (- 10 pts if it does not)
  • Each method does what it is supposed to do (80 pts)
  • Source code follows our Java Style Guide (10 pts)
  • Appropriate documentation including javadoc tags (10 pts)
Turn In
  • Cover page - Your project must have a cover page that includes your name, a title, an appropriate picture and the following signed pledge. "I pledge that this work is entirely mine, and mine alone (except for any code provided by my instructor). " You are responsible for understanding and adhering to the School of CIS Guidelines for Academic Honesty.
  • Source code - a printout of your source code (with your name).
  • Be prepared to demo your project during lab.
Late Policy

Projects are expected to be turned in on time. However, you are encouraged to complete a project even if you must turn it in late.

  • 1 weekday late (-20 pts)
  • every subsequent weekday is an additional -10 pts
  • Saturday and Sunday are free days