Starter Project

Suggested reading: Section 21.5

The problem

Start by downloading this archive. Inside the archive you will find seven text files. Each text file contains a list of readings for a set of devices. Each device is identified by a letter, and the reading for that device on the given day appears after that letter.

Not have all devices will have readings recorded on any given day. Your problem in this assignment is to construct a list of the devices that have readings present on all seven days.

Make a project

Start by making a new project in NetBeans. To do this, select the New Project... command from the File menu in NetBeans.

In the new project dialog select "Java with Ant" from Categories and Java Application from the Projects list.

On the next screen make note of the location where NetBeans wants to create that new project folder. You will need to access that folder in the next step.

Once you have created the project folder, copy the text files from the archive provided into that project folder.

How to solve the problem

Your solution will consist of a simple Java class with a main() method in it. All of the code you will write for this assignment will go into that main() method.

To solve our problem we are going to make use of a HashMap class. A Map class maps keys to values. For this assignment you will be working with a HashMap<String,Integer> that maps the device names to counts of how many times a given device appears in the files.

You can add a new entry to a map by using the put() method. The put() method takes two parameters: the key you want to work with and the value you want to assign to that key. Start by using the put() method to store a value of 0 for each of the keys from 'A' to 'Z'.

Next, set up a loop that iterates over all seven of your files. For each entry in the file, use the map's get() method to look up the current count of the number times that particular device has appeared so far. Increment that count by 1 and store the new count back in the map by using the put() method.

Once you have read all seven of the input files and collected counts from them, write a loop that iterates over all of the device names from 'A' to 'Z'. Print the name of any device that has a count of exactly 7.

How to turn in your work

When you are done writing your program, compress the project folder into an archive and send me that archive as an attachment to an email.