CS 11 – April 1 Review steps for lab #3 Finish monthly climate problem. Array of objects Convenient to organize into 3 source files. Searching an array of objects is similar to searching array of numbers, or characters in a string. findMax() – search array for an attribute findMin() – search array for an object No class tomorrow; please submit homework design by Thursday.
Team.java Declare attributes: 1 string, 3 int Declare constant GOOD = 95 Initial-value constructor This is where attributes are initialized. findTotalPoints() isGood() Since we need to know the number of points, we need to call findTotalPoints( ) within isGood( ). You don’t need to make points an attribute, because it can be derived from other values.
Driver.java Ask user for number of teams Use nextInt( ) to read this number numTeams Initialize count and numGood to 0 Set up while-loop to run numTeams iterations: Ask user for a name and 3 numbers Read string and 3 integers Create team object by calling Team constructor Call toString( ) to print out the object. Call isGood( ), and if true, increment numGood Print the number of good teams
Driver2.java Change program to use file I/O. Ask user for names of input & output files Read these names from keyboard. Open the input and output files. Read first number from file numTeams Take out prompt asking user for this number Inside while loop: Change the scanner calls so we read from the input file instead of from the keyboard
Monthly climate The most interesting part of the program is the Month class. Constructor reads input file. Each line corresponds to one day. Read the 4 numbers, create Day object, put in array. Traversing an array I implemented findMax( ) and findMin( ) differently so you could see the difference between finding an object versus just one attribute value. findTotalRain( ) just sums the rain attribute for each Day.