public class PATollBoothA implements TollBooth{ // Array option // Instance Variables // private int receiptsSinceCollection; // private int trucksSinceCollection; these are now identified somewhere else //create the Arrray private Trucks[] PassingTrucks; int z; // to identify which index position within the array // Methods public PATollBooth() { PassingTrucks = new Trucks[10]; //instantiating PassingTrucks as an Array // we can delete this *** trucksSinceCollection = 0; // Clear out totals // we can delete this *** receiptsSinceCollection = 0; } public void calculateToll(Truck truck) { PassingTrucks[z] = truck; //Adding object truck to the array (axle,weight) z++; if (z > 9) z = 9; //to overwrite the tenth element in the array int axles = truck.getAxles(); int totalWeight = truck.getTotalWeight(); int tollDue = 5*axles + 10*(totalWeight/1000); // Toll calculation System.out.print("Truck arrival - axles: "); System.out.print(axles); System.out.print(" total weight: "); System.out.print(totalWeight); System.out.print(" Toll due: "); System.out.println(tollDue); } public void onReceiptCollection() { System.out.print("*** Collecting receipts ***"); displayData(); PassingTrucks = null; // empties array //we can delete this *** trucksSinceCollection = 0; // Clear out totals //we can delete this *** receiptsSinceCollection = 0; } public void displayData() { Truck t; int trucksSinceCollection = 0; int receiptsSinceCollection = 0; int truckaxles; // to declare datatype int trucktotalWeight; // to declare datatype int trucktollDue; // to declare datatype for(int i = 0; i < z; i++) { t = PassingTrucks(i); //Toll calculation truckaxles = t.getAxles(); trucktotalWeight = t.getTotalWeight(); trucktollDue = 5*axles + 10*(totalWeight/1000); //Totaling Tolls trucksSinceCollection = trucksSinceCollection + 1; receiptsSinceCollection = receiptsSinceCollection + trucktollDue; } // to end loop started after while statement System.out.print("Totals since last collection - Receipts: "); System.out.print(receiptsSinceCollection); System.out.print(" Trucks: "); System.out.println(trucksSinceCollection); } }