Java Environments

Topics: Date and time notation by country, 24-hour clock, 12-hour clock Pages: 14 (1345 words) Published: April 3, 2011
CSCI 1101
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 expired by "+minutesPassedExp+" minutes";
else
meterDetails = "Your meter has "+minutesRemaining+" minutes remaining.";
return meterDetails;
}
}

ParkingTicket.java
//Object representation of a parking ticket.
public class ParkingTicket
{
private int fineAmount;
private ParkedCar illegalCar;
private String copName;
private int copNum;

//Constructor for the ticket.
//In addition to assigning given-values to the declared variables
//this method calculates the fine's amount.
public ParkingTicket(ParkingMeter meter, ParkedCar car, String name, int number)
{
illegalCar = car;
fineAmount = 25+meter.passedExpiration()/60*10;
copName = name;
copNum = number;
}

//Prints ticket information.
public String toString()
{
String ticketInfo;
ticketInfo = "Car Information\n\n"+illegalCar+"Fine amount: "+fineAmount+"\n\nOfficer Name: "+copName+"\nOfficer #: "+copNum;
return ticketInfo;
}
}

PoliceOfficer.java
//Object representation of a police officer's identity.
public class PoliceOfficer
{
private String officerName;
private int officerBadge;

//Constructor for the police officer, with given name and badge number.
//Assigns declares variables to the given values.
public PoliceOfficer(String name, int badge)
{
officerName = name;
officerBadge = badge;
}

//Checks if the meter is expired or not.
public boolean examineMeter(ParkingMeter meter)
{
if(meter.getMinutesPassed() > meter.getMinutesPurchased())
return true;
else
return false;
}

//Gives a parking ticket to the illegally parked car.
public ParkingTicket giveTicket(ParkingMeter meter, ParkedCar car)
{
ParkingTicket hisTicket = new ParkingTicket(meter, car, officerName, officerBadge);
return hisTicket;
}
}

TicketDemo.java
//Demonstrates the collaboration of the ParkedCar, ParkingMeter //ParkingTicket and PoliceOfficer classes.
public class TicketDemo
{
public static void main(String[]args)
{...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Java Essay
  • Java Sevelets Tutorial Research Paper
  • Notes Java Essay
  • Essay on Java Cis Assignment 1
  • Java Programming- Chinmay Essay
  • Java Model Test Papers for Icse
  • Java Exception Handling Essay
  • Computer Guess Paper for C++ and Java

Become a StudyMode Member

Sign Up - It's Free