{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

program3

# program3 - Program 3 Name Xin Chi*Class Comp 401...

This preview shows pages 1–3. Sign up to view the full content.

/** * Program 3 ** Name: Xin Chi *Class Comp 401 I *nstructor Hedlund *Section 1 Pledge: * I have neither given nor received unauthorized aid on this program. * */ public class program3 { private static int[] dht; public static void main(String[] args) { testDaysAbove89(); testLastDayAbove89(); testLongestHotSpell(); } // Pre: temp.length > 0 // Post: return number of days for which the temperature // was above 89 public static int daysAbove89(int[] temp) { int count = 0; for (int t : temp) { if (t > 89) { count++; } } System.out.println("days above 89 is " + count); return count; } // Input Expected Return // [90, 78, 91, 42, 99] 3 // [78, 42, 31, -5] 0 // complete this test plan public static void testDaysAbove89() { dht = new int[] { 90, 78, 91, 42, 99 }; daysAbove89(dht); dht = new int[] { 78, 42, 31, -5 }; daysAbove89(dht); dht = new int[] { -30, 0, 90, 89 }; daysAbove89(dht); dht = new int[] { 89 }; daysAbove89(dht); dht = new int[] { 90, 91, 89, 88, 95, -3, 97 }; daysAbove89(dht); } // Pre: temp.length > 0 // Post: return the index of the last day in the array

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
// for which the temperature was above 89 decrees. public static int lastDayAbove89(int[] temp) { int index = -1; for (int i = 0; i < temp.length; i++) { if (temp[i] > 89) { index = i; } } if (index == -1) { System.out.println("There is no day for which the temperature was
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}