/** * Author: Josiah Yoder et al. * User: yoder * Class: SE1011-011 * Lesson: Week 9, Day 1 */ import java.util.Scanner; public class Example011_9_1 { public static void main(String[] ignored) { // Primitive array approach double[] pointsNorth; pointsNorth = new double[4]; double[] pointsEast = new double[4]; // New improved object approach Point011_9_1[] points = new Point011_9_1[4]; // Competition scores // 50-hotdogs // high score for the year double[] winnersTimeMinutes = new double[5]; winnersTimeMinutes[0] = 3.5; winnersTimeMinutes[1] = 2.5; winnersTimeMinutes[2] = 2.6; winnersTimeMinutes[3] = 1.8; winnersTimeMinutes[4] = 3.4; // Can only use this form on the line where the variable // is declared. double[] winnersTimeMinutes2 = {3.5, 2.5, 2.6, 1.8, 3.4}; System.out.println("The 5th annual winner's time is: "+ winnersTimeMinutes[5-1]); // In-class activity: Write out all winner's times for // all competitions // Solution: (Thanks to Pat for sharing his solution here) for(int i = 0; i < 5; i++) { System.out.println(winnersTimeMinutes[i]); } // Upgraded version that uses "length" of the array for(int i = 0; i < winnersTimeMinutes.length; i++) { System.out.println(winnersTimeMinutes[i]); } final int MAX_NUM_SCORES = 100; double[] scoresMinutes = new double[MAX_NUM_SCORES]; double input; int numScoresEntered; Scanner in; int i; // BUGGY VERSION AT END OF System.out.println("BUGGY version"); input = 0; in = new Scanner(System.in); i = 0; do { System.out.println("Enter the score for year "+(i+1)); input = in.nextDouble(); if(Math.abs(input) >= 0.001) { scoresMinutes[i] = input; } i++; } while(Math.abs(input) >= 0.001 && i= 0.001) { scoresMinutes[i] = input; i++; } } while(Math.abs(input) >= 0.001 && i 0, we will always want to ask the user // at least one question. System.out.println("Enter the score for year "+(i+1)); input = in.nextDouble(); while(Math.abs(input) >= 0.001 && i < scoresMinutes.length) { scoresMinutes[i] = input; i++; System.out.println("Enter the score for year "+(i+1)); input = in.nextDouble(); }; numScoresEntered = i; for(i=0; i