Difference between revisions of "Student Record List With Parallel Arrays"

From CompSciWiki
Jump to: navigation, search
Line 21: Line 21:
 
The first array stores a list of student names and the second array stores a list of the corresponding student's grades.
 
The first array stores a list of student names and the second array stores a list of the corresponding student's grades.
  
First we will print the current list of students and their corresponding grades. It is good programming ediquette seperate sections of your code into methods so that your program is organized in a legible fashion. Create a new method (ex: printList()) and pass the two array as parameters (String [] students and int [] grades). Make note that we are simply printing the arrays so no return value.
+
The first task is to print the current list of students and their corresponding grades. It is good programming ediquette seperate sections of your code into methods so that your program is organized in a legible fashion. Create a new method (ex: printList()) and pass the two array as parameters (String [] students and int [] grades). Keep in mind that we are simply printing the arrays so there are no return value.  
 +
 
 +
You should have something that looks like this,
 +
<pre>
 +
public static void printList(String [] students, int [] grades) {
 +
}
 +
</pre>
 +
 
 +
Start writing your print list method with a for loop. As a reminder, arrays start with the index
  
 
|SolutionCode=
 
|SolutionCode=

Revision as of 21:53, 6 April 2010

Back to the Program-A-Day homepage

Problem

Given two parallel arrays, where the first array stores the a list of student's names and the second array stores the list of grades, print out the name of the student and their corresponding grade. Find the student with the highest grade and the student with the lowest grade and print the results. Use a honoursRoll[] boolean array to store true if the corresponding student is eligible for honours (>=80) and print the results.

 

Wiki bench01.jpg


Solution

In this example, you are given two parallel arrays with 10 elements in each array,

String [] students = {"Joey Chase","Alan Gibbs","Ellen Kauffman","Thomas Lembeck",
"Alexa Bright","Seth Benson","Terry Logan","Keven Gail","Shelley Fryman","Jill Beckam"};

int [] grades = {90,63,77,85,91,54,82,55,53,89};

The first array stores a list of student names and the second array stores a list of the corresponding student's grades.

The first task is to print the current list of students and their corresponding grades. It is good programming ediquette seperate sections of your code into methods so that your program is organized in a legible fashion. Create a new method (ex: printList()) and pass the two array as parameters (String [] students and int [] grades). Keep in mind that we are simply printing the arrays so there are no return value.

You should have something that looks like this,

public static void printList(String [] students, int [] grades) {
}

Start writing your print list method with a for loop. As a reminder, arrays start with the index

Code

Solution Code

Back to the Program-A-Day homepage