OverviewScheduleAnnouncementsResourcesAssignmentsHome

CSC 121: Computer Science I, Spring 2005

In-Class Exercise: Arrays

Simulation Statistics with Arrays

Goals:
To conduct an experiment by collecting data in an array and manipulating that array.
Getting started:
The Steps of the Lab:
  1. Use the bowling simulation to find the average game score for your bowler. (Test each step as you complete it)
    Do

    Define a new class field called gameResults as an int array. Write code in the class constructor to create an instance of gameResults with 1000 entries.

    Write a method, playAllGames, that has an int parameter, numGames (which must be less than or equal to 1000), that will play numGames number of games, storing the result of each in an appropriate cell of the gameResults array. The result of the first game is stored in cell 0, the second in cell 1, the third in cell 2, and so on. Once all games are played, playAllGames should call the method displayResults, described below.

    Write a method called displayResults that displays the score of each game played and the average of those scores. displayResults will have an int parameter, numGames, representing the number of games played.

    Write a method called getMax that returns the highest score bowled in the experiment. getMax should have a parameter, numGames, just like playAllGames and displayResults.

    Play

    Test all of this part by playing 10 games, 100 games, 1000 games several times, calling getMax after each.

    Do

    Write a method called twoInARow that returns true or false according to whether or not there are two games in the gameResults array with the same score that are in adjacent cells of the array.

OverviewScheduleAnnouncementsResourcesAssignmentsHome

Valid HTML 4.01!Valid CSS!DePauw University , Computer Science Department , Spring 2005
Maintained by Brian Howard ( bhoward@depauw.edu ). Last updated