Computer Science II
Assignment No. 2
Date Given: January 31, 2011
Due: February 18, 2011
David Mongrain
B00554371
Parking ticket simulator
ParkedCar.java
//Object representation of a car. public class ParkedCar
{
private String carMake; private String carColor; private int carLicense;
//Constructs the car, with given car make, car color, and car license.
//Sets the declared instance variables to their respective given values; public ParkedCar(String make, String color, int license) { carMake = make; carColor = color; carLicense = license; }
//This prints the information of the car. public String toString() { String carInfo; carInfo = "Car Make: "+carMake+"\nCar color: "+carColor+"\nLicense Number: "+carLicense+"\n"; return carInfo; }
}
ParkingMeter.java
//Object representation of a parking meter. public class ParkingMeter
{
private int minutesPurchased; private int minutesPassed; private int minutesPassedExp;
//Constructor for Parking Meter with //amount of minutes purchased as only parameter. public ParkingMeter(int minutes, int timePassed) { minutesPurchased = minutes; minutesPassed = timePassed; }
//Get-method for the minutes paid-for. public int getMinutesPurchased() { return minutesPurchased; }
//Get-method for the time passed, in minutes. public int getMinutesPassed() { return minutesPassed; }
//This method gets the minutes passed expiration. public int passedExpiration() { minutesPassedExp = minutesPassed - minutesPurchased; return minutesPassedExp; }
//Prints (if the meter is expired) how long the meter has been expired.
//Otherwise (if the meter is still good), prints the remaining time on the meter. public String toString() { int minutesRemaining; minutesRemaining = minutesPurchased - minutesPassed; String meterDetails; if(minutesPassed > minutesPurchased) meterDetails = "Your meter has