CSC-220 HW9 Babyname V2.0 Application

Due:  Monday, December 17 9:50am

This represents the last minute this course is legally open.  No submissions afterward.

The final homework assignment will be a complete rewrite of the babyname application.  V1.0 had serious performance problems and buyers of the product want their money back.

V1.0 used an ArrayList to build the babyname counts.  V2.0 is going to scrap that design and use a data structure called a TreeMap.

Read Chapter 21 Sets and Maps to get a handle on the built in Collections Data Structure available in standard Java.

Hints and Tips (Friday 12/7): 

After producing a working V2.0 that is substantially faster than V1.0, I want to share my thoughts to help you code your assignment.

  • DO NOT DELETE THE BABYNAME CLASS!!!  I was wrong in my initial assessment of the project. Keep the class as is.  Do not change it at all.
  • In the BabyNameStats class, change the boys and girls fields to be of type TreeMap<String, Integer>.
  • Add this code to your class.  It sorts the TreeMap entries by the value field.  It uses a Comparator object to do the sorting. 
  • Do most of your coding in the generateStats method.  Create local boys and girls TreeMaps and load the TreeMaps with names and counts.  The problem is the normal TreeMap with no Comparator orders the entries by key which is the name.  We really need to have them ordered by value which is the count.  Call the method that generates value ordered entries on the local TreeMaps and store the new maps in the boys and girls class fields.
  • Do not remove the concept of an ArrayList<BabyName> from V2.  I was a bit over zealous about removing it entirely.  In the getTopNames method have it still return an ArrayList<BabyName>.  But this time use this code to load the Arraylist with the top BabyNames:
  • Keep all the other code intact and watch V2.0 fly!

CSC-220 HW8 Implementing Linked List Methods with Solution

Due: Monday, November 26 11:59pm


Download the modified source code for chapter 24.  In the file, there are methods that specify you implement their logic.  Please do so.

These methods have the following headers:

  • public boolean contains(Object e);
  • public E get(int index);
  • public int indexOf(Object e);
  • public int lastIndexOf(E e);
  • public E set(int index, E e);

Use the  file to test your implementation.

CSC-220 Exam #4 on Friday, Nov. 30

Let’s have our next exam covering just chapters 18 (Recursion) and 24 (Linked Lists) on Friday,  Nov. 30.   It is a multiple choice exam so come early to class and bring a pencil.

Go here for sample quizzes:


Last Day to Withdraw From Classes

Tuesday, November 27.

If you haven’t been keeping up with the work, have a low grade average, or have missed a multitude of classes, please drop the class. I will issue a failing grade if your average is below a 60.

If the course has an associated lab, please drop that as well.

Unless you have a medical issue that can be verified by the Dean of Students, there are no extensions, extra work, or any other way for you to extend this semester.

CSC-220 HW5 Baby Names Application with Solution

Solution that includes Nam’s Suggestion

Due: Monday, Oct 29 11:59pm

This assignment is just way too cool.  It exercises many of the topics we discussed his semester; not to mention, it is also a useful utility.  Start coding now!  This is not the type and homework you can finish two hours before the deadline.

Warning! Do not create a GUI if the basic operation of the classes described below hasn’t been properly developed.  Don’t waste time on a GUI that doesn’t work.  You will not get extra credit for a dysfunctional GUI.  If you code the classes properly, and they work in a command line app, then you should be able to plug and play these classes in a GUI that calls their public methods.  That will give you extra credit.

The following database of Baby Names (Zip) is maintained by the federal government and is located here:

It contains text files of names from 1880 to 2017.  Each file is a CSV file capable of being imported into any popular spread sheet.

To use this data, download, unzip the file, and place the contents in a package called babynames in your project.  Alternatively, you may access these same files online from my website located here:

Each line of the text file contains the following info:


where name is the baby’s name, their sex (M/F), and the number of babies born with that name.

Since this is a comma separated value (CSV) file, use the following sample program to read a data file:

If you choose not to read the files directly from the server, then copy the data files into your project.  Make a package in the project to hold these files.  It’s a fairly hefty database by our standards, 23MB!

Your application will use our application template to prompt for start and ending years, as well as an integer representing the top number of names to display.  The app will read data from those years and display the top number of names of name, sex, and the total number of babies born with that name in the specified range.  A JavaFX program would be even better if you know the technology.

Error check these inputs.  Year input allow for only integers and must be positive.  The start year must be ≤ to the end year.  Years input must map to a datafile.  For example, you can’t enter a 1879 year as there is no such file.  You can’t enter 2018 as that year hasn’t happened or finished yet.  Common sense on the inputs!

For instance, you enter 2010, 2015, 3.  What the app displays is (Data is totally contrived!):


  1. Tony, 23456
  2. Bob, 22123
  3. John, 20123


  1. Mary, 23453
  2. Joan, 21345
  3. Amelia, 19456

The heart of this application is an ArrayList!  Actually two, one for males and females.

BabyName class Specifications

You will create a class called BabyName that contains the instance variables, name, and number.  This class must contain the following methods:

equals – Create a standard equals method.  It is this equals method that the ArrayList uses to determine if a name is already in the list. Remember NO duplicates!  If a name is already in the list, you will simply access the BabyName object for that name and add to the number the number of additional babies with that name.

compareTo – The BabyName class must implement the Comparable Interface.  It is the comparable interface method compareTo that you will use to sort the ArrayLists in descending order.  Look at the number field in the BabyName.  Base your logic on that first.  If you are comparing two BabyNames with the same numbers, then use the Name to decide which goes first, alphabetical order.

toString – You know every class that you intend to print out needs one.  Make sure you output the name and number for the baby name.

BabyNameStats Class Specifications

Two private ArrayLists of BabyName.  One for males and one for females.  Have the constructor null out these fields.

A public Constructor that takes 3 int values:

  • Start Year
  • End Year
  • Number of Top Names desired.

and saves these values as fields.  Error checking these values would be appropriate.  If bad values were passed, throw an exception.

A private method that creates and builds the male and female array lists.  These lists could potentially have 10,000+ names.  Use Collections.sort to sort the ArrayLists by the number people who have a particular name.  If your names are appearing in ascending order, small numbers first, then you can use the Collections.reverse method to rearrange the list.

A public method called getTopMaleNames() that returns an arraylist of males that is as larges as “Number of Top Names desired”.  This method will call your private method if the property that holds the male arraylist is null.  If it isn’t null, then you’ve already went through the logic to generate the top male names and their counts so don’t do it again.  Just return an array list of the top names.  It is ok and efficient to also have your logic build the female array list since the probability of getting and top females is almost certain.

Another public method called getTopFemaleNames() that returns an arraylist of females that is as larges as “Number of Top Names desired”. Same basic steps as described for getTopFemaleNames().

CSC-220 Exam #2 Friday, Nov. 2

Let’s have our next exam covering chapters 9, 10, and 11 on Friday, Nov. 2. It will be an in class exam.

It’s a Closed Book / Closed Notes Multiple Choice Exam. COME EARLY TO CLASS AND BRING A PENCIL.

Go here for sample quizzes:

CSC-220 HW2 Arrays Assignment

Due: Friday, Sept. 21, 2018  11:59pm

Given two strings s and t, determine if they are isomorphic.

Two strings are isomorphic if the characters in s can be replaced to get t.

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.

Example 1:
Input: s = “egg”, t = “add”
Output: true

Example 2:
Input: s = “foo”, t = “bar”
Output: false

Example 3:
Input: s = “paper”, t = “title”
Output: true


Incorporate the Project Template for those writing a command line program.  CSC-112 graduates can write a GUI to do this problem for extra credit.  Don’t forget that knowledge. 


Only use the material up to and including Chapter 7 on single dimension arrays.  If you include data structures that are beyond what we covered, then you will be asked to demo your code to class and explain its operation.


To convert a string to an array, use the String .toCharArray() method.

CSC-220 Chapter 7 Searching and Sorting Examples

Sorting and Searching V1:

Sorting and Searching V2 using Arrays methods:

Sorting Using BinarySearch routine (updated 9/17/18):

String Sorting:

String Sorting V2 With Interfaces and Lambdas

CSC-220 – Supplemental Video Course Series

Optional resources, but highly suggested supplements for this course.  I’ll be using these video series as a supplement to my lectures this semester:

These courses can be purchased for as little as $9.99.  Not bad!

Links and Resources for Java Courses

Liang 11th Edition Resources

Common Resources

Sign up for a GitHub Account

If you going to be a programmer, then github is a site you’ll need to use.

Go here: and create an account for yourself.  We will be using github for homework submissions.

In particular the part of github we’ll  be using is the gist function located here:

You can submit multi-file projects under just one URL! You also have a record of all your work in one convenient location.