Class 1, Part 2 | Intro to Java 30-IT-396 |
Example: GoBearcats
/**
*
* @author default
*/
public class GoBearcats {
// Declare an array for student names.
int score[][] = new int[18][2];
/**
*
* Creates a new instance of GoBearcats
*
* Initialize the array to a the scores
of the first 17 games.
* Array 0 is the Bearcat score; 1 is the
opponent score.
*
* Scores:
Nov 10 NORTHERN KENTUCKY (EXH.) WXIX-TV W, 81-53
Nov 12 KENTUCKY WESLEYAN (EXH.) W, 96-66
Nov 16 at Oklahoma St ESPN L, 62-69
Nov 20 WRIGHT ST WXIX-TV W, 83-54
Nov 24 UNLV ESPN2 W, 74-61
Nov 28 DAYTON WXIX-TV W, 77-55
Dec 1 DUQUESNE WXIX-TV W, 74-41
Dec 8 COPPIN ST WXIX-TV W, 90-39
Dec 10 TOLEDO WXIX-TV W, 68-55
Dec 14 at Xavier ESPN W, 75-55
Dec 17 RICHMOND (LAS VEGAS CLASSIC) WXIX-TV W, 77-46
Dec 20 vs. UL Monroe (Las Vegas Classic) Fox Sports W, 102-66
Dec 21 vs. Mississippi St (Las Vegas Classic) Fox Sports W, 90-56
Dec 22 vs. Purdue (Las Vegas Classic) Fox Sports W, 79-62
Dec 29 vs. Akron (Rock-N-Roll Shootout, Cleveland, Ohio) WXIX-TV
W, 73-57
Jan 5 at East Carolina * WXIX-TV W, 72-62
Jan 8 CHARLOTTE * WXIX-TV W, 71-58
Jan 12 at Houston * WXIX-TV W, 83-62
*
*/
public GoBearcats() {
score[0][0] = 81;
score[0][1] = 53;
score[1][0] = 96;
score[1][1] = 66;
score[2][0] = 62;
score[2][1] = 69;
score[3][0] = 83;
score[3][1] = 54;
score[4][0] = 74;
score[4][1] = 61;
score[5][0] = 77;
score[5][1] = 55;
score[6][0] = 74;
score[6][1] = 41;
score[7][0] = 90;
score[7][1] = 39;
score[8][0] = 68;
score[8][1] = 55;
score[9][0] = 75;
score[9][1] = 55;
score[10][0] = 77;
score[10][1] = 46;
score[11][0] = 102;
score[11][1] = 66;
score[12][0] = 90;
score[12][1] = 56;
score[13][0] = 79;
score[13][1] = 62;
score[14][0] = 73;
score[14][1] = 57;
score[15][0] = 72;
score[15][1] = 62;
score[16][0] = 71;
score[16][1] = 58;
score[17][0] = 83;
score[17][1] = 62;
}
/**
* printResults
*
* Compares the multi-dimensional array.
Prints win or loss, depending on the score.
*
* @author jonesbr@email.uc.edu
* @version 1.0
*/
void printResults() {
// variables to keep
track of the total points.
int bearcatTotal = 0;
int oppositionTotal
= 0;
// A for loop to display
win or loss.
for (int i = 0; i <
score.length; i++) {
if (score[i][0] > score[i][1]) {
// Add 1 because Java starts counting with 0, we start with 1.
// Enclose in parens so that Java adds, not concatenates.
System.out.println("Game " + (i + 1) + " UC wins!");
} else {
System.out.println("Game " + (i + 1) + " UC loss. That's rare!");
}
// Accumulate the total score.
bearcatTotal += score[i][0];
oppositionTotal += score [i][1];
}
// Print some figures
to remind us how kool we are.
System.out.println("Bearcat
total points: " + bearcatTotal);
System.out.println("Opposition
total points: " + oppositionTotal);
}
/**
* public static void main(String args[])
*
* instantiates the class from the command
line.
* calls printNames to print the output.
*
* @author jonesbr@email.uc.edu
* @version 1.0
*
*/
public static void main(String args[]) {
GoBearcats goBearcats
= new GoBearcats();
goBearcats.printResults();
}
}
Created by: Brandan
Jones January 4, 2002
Updated February 4, 2003