/* * PotholeDriver.java * Midterm 2 exam for CS107, Spring 2009 * * Be sure to comment out sections of code that don't work before * you turn in your solution, since you get no points if your * program doesn't compile. See instructions for each of the problems * below. * * DETAILS: This problem has to do with sending out crews to fix potholes that have * been reported to the City of Chicago. The same crew can be sent out * to fix potholes that have an address on the same street within a block * of each other. In other words, 4213 and 4248 would be on the same block * since the first two digits are the same. */ /* Running this program will output this: * * Name: Dale Reed * Midterm Exam 2, CS 107, Spring 2009 * * Pothole #1 reported 3/11/2009, at 5230 W. Rooseveldt Rd, severity 3 * Pothole #2 reported 3/1/2009, at 3520 N. Michigan Ave, severity 2 * Pothole #3 reported 1/1/2000, at 1000 State St., severity 1 * Pothole #4 reported 1/1/2000, at 5225 W. Rooseveldt Rd, severity 5 * * Same crew can fix: * Pothole #1 reported 3/11/2009, at 5230 W. Rooseveldt Rd, severity 3 * Pothole #4 reported 1/1/2000, at 5225 W. Rooseveldt Rd, severity 5 * * Done with program. * */ public class PotholeDriver { public static void main(String args[]) { // Replace my name with yours in the statement below System.out.println( "Name: YOUR NAME!!! \n" + "Midterm Exam 2, CS 107, Spring 2009 \n" ); // Create some dates, and use them to create some pothole records Date5 date1 = new Date5( 3,11,2009 ); Pothole pothole1 = new Pothole(1, date1, 5230, "W. Rooseveldt Rd", 3); Pothole pothole2 = new Pothole( pothole1); // create a pothole entry based on an existing one Date5 date2 = new Date5( 3,1,2009); pothole2.setDate( date2); pothole2.setAddress( 3520); pothole2.setStreet( "N. Michigan Ave"); pothole2.setSeverity( 2); Pothole pothole3 = new Pothole(3); Pothole pothole4 = new Pothole(4, 5225, "W. Rooseveldt Rd", 5); // display Potholes System.out.println( pothole1); System.out.println( pothole2); System.out.println( pothole3); System.out.println( pothole4); // display potholes close by each other System.out.println("Same crew can fix: "); if( pothole1.closeBy( pothole2) ) { System.out.println( pothole1); System.out.println( pothole2); System.out.println(); } if( pothole1.closeBy( pothole3) ) { System.out.println( pothole1); System.out.println( pothole3); System.out.println(); } if( pothole1.closeBy( pothole4) ) { System.out.println( pothole1); System.out.println( pothole4); System.out.println(); } System.out.println( "Done with Problem 1 for midterm #2 \n" ); // Only go on to this next part (Problem 2) if you have the first part done. // Delete the block-style comments to activate this next section of code. /* // Create an array of PotHole entries Pothole[] potHoles = new Pothole{ new pothole(2), new pothole(1), new pothole(5), new pothole(1), new pothole(3), new pothole(1), new pothole(5), new pothole(2), new pothole(4), new pothole(4), new pothole(1), new pothole(2), new pothole(1), new pothole(4), new pothole(5), new pothole(5), new pothole(4), new pothole(2), new pothole(1) }; // sort the potholes into ascending order (first potholes of severity 1, then 2, etc) // You must write the method within this class below so that the code below works. sortArray( potHoles); // display contents of array, which should now be in order for( int i=0; i