0% found this document useful (0 votes)
22 views

Programming 1A: (PROG5121)

The document discusses using parallel arrays to represent tabular data. It provides an example of using parallel arrays to store information from a dog show competition - one array stores the dog names, another stores the scores from round 1, and a third stores the scores from round 2. Code is shown to initialize the parallel arrays and print out the data in a formatted manner using a for loop. An exercise is provided to create a DogCompetition class that implements this parallel array example. Finally, a class activity is described to create an EmployeeInformation class that prints employee data from four parallel arrays using printf formatting.

Uploaded by

Dzudzi Manyuha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Programming 1A: (PROG5121)

The document discusses using parallel arrays to represent tabular data. It provides an example of using parallel arrays to store information from a dog show competition - one array stores the dog names, another stores the scores from round 1, and a third stores the scores from round 2. Code is shown to initialize the parallel arrays and print out the data in a formatted manner using a for loop. An exercise is provided to create a DogCompetition class that implements this parallel array example. Finally, a class activity is described to create an EmployeeInformation class that prints employee data from four parallel arrays using printf formatting.

Uploaded by

Dzudzi Manyuha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PROGRAMMING 1A

(PROG5121)
PARALLEL ARRAYS

BASED ON CHAPTER 8, FARRELL, J. 2019. JAVA PROGRAMMING.


9TH ED. 2019. COURSE TECHNOLOGY, CENGAGE LEARNING.
PARALLEL ARRAY REPRESENTATION
• Parallel arrays are several arrays with the same number of elements that work in tandem to
organize data.
• It is often necessary to represent data in a "table" form, as shown below, where the arrays represent
the data from a dog show.

The first array stores the


dog’s name.

The second array stores the


dog's score in round 1 of
the competition.

The third array stores the


dog's score in round 2 of
the competition.
PARALLEL ARRAY IMPLEMENTATION

• The table representation of the dog competition information can be implemented in Java as follows:

String[ ] dogname = {"Wally", "Skeeter", "Corky", "Jessie", "Sadie"};


int[ ] round1 = {18,22,12,17,15};
int[ ] round2 = {20,25,16,18,17};
• The dog competition information can then be printed out as follows:

for (int index = 0; index < dogname.length; index++) {


    System.out.print(dogname[index] + " ");
    System.out.print(round1[index] + " "); EXERCISE
1. Create a class called
    System.out.println(round2[index]); DogCompetition.
2. Code the main() method
}
with the code given here.
3. Run your program to see
the parallel array output.
CLASS ACTIVITY 9
• Write a Java class called EmployeeInformation to print the output shown below on the console.

• Your main() method must use four parallel arrays, each initialized with the values shown under the
four columns shown by the output below.

• Use the printf() method to format and print the array elements in each column as indicated.

printf() formatting requirements


ID - an integer element padded with 4
zeroes.
Name – a string element occupying
10 positions.
Department – a string element
occupying 10 positions.
Pay – a double element having 2
decimal places.

You might also like