Lab 1 - Intro to Programming Review

In this lab, you'll review some of the topics that you learned in 1303.  Specifically, you'll develop a small application that manages a contact list collection (similar to Outlook).

The lab will have multiple steps, and you should try and perform the lab steps on your own, but certainly click through the how-to links to see step-by-step walkthroughs on how to complete each step.

Here are the steps:

  1. Define a "person" class that has attributes like name, phone number, address, etc.
  2. Prompt the user for how many people to add to the collection
  3. Loop through and read in the information and add the new contact into the collection
  4. Display all the contacts

Notice that this isn't a very robust system (we'll develop it further this semester), but it's a start.  We'll use an array as our data structure for this lab.  And we'll use good modularity, breaking our program up into multiple methods where appropriate.


Step 1 - Define the Person class

First, we need to define the person class.  This class should have attributes (go ahead and make them public) as follows:

Once you have the attributes, define a constructor that initializes each attribute to a default value; use things like "no name" and "nowhere street", etc. for these values.

Click this how-to to see a step-by-step solution for this part of the lab.


Step 2 - Prompt the user and define the array

Now that you have your class defined, we need to prompt the user for how many contacts they want to store in the program.  Once we have this information, we can declare an array large enough to hold these people's contact information.

Recall that you define an array like this:

TYPE[] NAME = new TYPE[SIZE];

where TYPE is a variable type (or class type), NAME is the variable's name, and SIZE is how large of an array you want.

So if we want to define an array of 30 person instances, we would do something like this:

Person[] MyContacts = new Person[30];

And of course, you can use a variable for the size... so first prompt the user for the size, then read in an int from the user and pass this int as the size for your array declaration.

Click this how-to to see a step-by-step solution for this part of the lab.


Step 3 - Looping

Now that you have the person class defined and an array large enough to hold the information, you need to write a loop to read in the information from the user.  This loop should repeat as many times as the user requested (based upon the number of people they wanted), and we know what that value is, so a FOR loop would be best here.

Write a FOR loop that repeats SIZE times.  Prompt the user for the contact information and create a new person and place it in the appropriate spot in the array each time through the loop.  Thus when your loop is over, the array should be filled with all the people that the user typed in.

I'd recommend creating a GetInformation method that prompts the user and reads in the information.

Click this how-to to see a step-by-step solution for this part of the lab.


Step 4 - Display all the contacts

And now that the looping is over and the information has been input, we can display it back to the user.  Write a loop (again, FOR is best) that displays the contents of the person array.

I'd recommend creating a PrintInformation method to display a person's information.

Click this how-to to see a step-by-step solution for this part of the lab.


Wrapping it all up

Click her to see the finished ZIPed solution.