//**************************************** // Program Name: parkingdriver.java * // Author: Pat Moss * // Date: Oct 10, 2005 Rev. 02 * // * // Driver for the calcparking.java class * //**************************************** // Create a calcparking object. // Park vehicles while there are more to park. // For each vehicle: // 1. Execute the calcparking object to // determine and display the parking fee. // 2. Accumulate the parking fee total // amount collected. // When all vehicles have been parked, // format and display the parking fee total // amount collected. import java.util.Scanner; import java.text.NumberFormat; public class parkingdriver { public static void main (String[] args) { boolean moretopark = true; double totalamtCollected = 0.0; String inputctrl = ""; calcparking calcparking1 = new calcparking(); Scanner scan = new Scanner(System.in); System.out.println ("parkingdriver.java rev. 02 by pat moss"); System.out.println (""); System.out.print ("Do you have more cars to park (Y or N)?"); inputctrl = scan.nextLine().toUpperCase(); if (inputctrl.length() < 1) moretopark = false; else if (inputctrl.charAt(0) == 'Y') moretopark = true; else moretopark = false; while (moretopark == true) // Use the sentinel false to terminate the loop { // calculate and display the parking fee information for this vehicle // and accumulate the total amount collected totalamtCollected += calcparking1.getInputData(); System.out.print ("Do you have more cars to park (Y or N)?"); inputctrl = scan.nextLine().toUpperCase(); if (inputctrl.length() < 1) moretopark = false; else if (inputctrl.charAt(0) == 'Y') moretopark = true; else moretopark = false; } // round the output value to two decimal places NumberFormat fmt = NumberFormat.getCurrencyInstance(); // format and display the total amount collected System.out.print ("Total amount collected: "); System.out.println (fmt.format(totalamtCollected)); System.out.println ("All Done..."); } }