/* University of Alberta (http://www.cs.ualberta.ca/) */ /* CMPUT114(2003-2004, Fall) http://www-csfy.cs.ualberta.ca/~c114/F03 */ // // Bus.java // CMPUT 114 // // Created by Vadim Bulitko on Mon Sep 15 2003. // Copyright (c) 2003 Vadim Bulitko. All rights reserved. // class Bus { // --------------------- Class variables ---------------------------- // Garage capacity private static final int garageCapacity = 2; // Number of buses in the garage private static int numInGarage = 0; // ---------------------- Instance variables ------------------------- // Status of the bus private boolean inGarage; // ---------------------- Methods ------------------------------------ // Creates a bus public Bus(boolean initialStatus) { inGarage = initialStatus; if (initialStatus) { numInGarage++; } } // Tells the garage capacity public static int askGarageCapacity() { return garageCapacity; } // Tells the current number of buses in the garage public static int askNumberInGarage() { return numInGarage; } // Orders the bus to leave the garage public void leaveGarage() { if (inGarage) { numInGarage = numInGarage - 1; inGarage = false; System.out.println("Leave the garage, Aye!"); } else { System.out.println("Unable to leave:" + " already outside of the garage..."); } } // Directs the bus to return to the garage public void returnToGarage() { if (!inGarage) { if (numInGarage < garageCapacity) { numInGarage = numInGarage + 1; inGarage = true; System.out.println("Return to the garage, Aye!"); } else { System.out.println("Unable to return:" + " the garage is full..."); } } else { System.out.println("Unable to return:" + " already inside the garage..."); } } // Checks the status of the bus public boolean checkStatus() { return inGarage; } }