Module Practice


examples


Classwork

1. Write a module printList that takes an array of Strings and prints each string from the array.

2. Write a module getNames that takes an int, makes an array of Strings of that size, and gets names from the user to fill the array before returning it

3. Write a module getGrades that, given an array of names, creates an array of the same size to hold grades, and then goes through asking the user for the grade for each person by name, and then returns the array of all the grades.

4. In a main module, ask the user how many students, and then use getNames to get a list of student names and store it in a variable so you can re-use it. Then use the other two modules you just wrote to first print the names, then get their grades (you will need the grades to be stored in a variable for later as well).

5. Write a module lookup that, given an array of strings, and a single string, returns the index where that name is found in the array, or -1 if it is not there.

6. Write a module lookupGrade that, given an array of grades, and array of names, asks the user for a name, and tells the user the matching grade or "Error, name not found" if that name is not in the array. (hint: think about how to use the lookup module!!!)

7. Go back to your main and after the code you already wrote there, write code to let the user look up a person's grade, based on the arrays of names and grades you already created and the modules you have to use as tools.