I have the following programming challenge to complete, and am stuck. I know what i have to do, which is to get information from the other three classes into the parking ticket class, and then print the parking ticket using an if statement if the time has expired. I am having difficulty understanding how to link the classes together... after the instructions, I have posted my four classes that I have created thus far.
Design a set of classes that work together to simlulate a police officer issuing a parking ticket. The classes to design are:
- ParkedCar class: simulates a parked car
This class knows the car's make, model, color, license number, and the number of minutes that the car has been parked.
ParkingMeter Class: simulates a parking meter.
- This classes only responsibility is to know the number of minutes of parking time that has been purchased.
-ParkingTicket class: Simulates a parking ticket
Responsibilities:
- To report make, model, color, and license number of the illegally parked car.
- To report the amount of the fine which is $25 dollars for the first hour or part of the hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is parked.
- To report the name and badge number of the police officer issuing the ticket.
-PoliceOfficer class: Simulates a police officer
Responsibilities:
- To know the police officer's name and badge number
- To examine a parked car object and a ParkingMeter object and determine whether the car's time has expired.
- To issue a parking ticket (generate a parkingTicket object) if the car's time has expired.
Write a program to test the classes as well.
import java.util.Scanner;
public class parkedCar
{
public static void main(String[] args)
{
String make;
String model;
String color;
double licenseNumber;
double minutesParked;
Scanner keyboard = new Scanner (System.in);
System.out.print("Enter the make of the car: ");
make = keyboard.nextLine();
System.out.print("Enter the model of the car: ");
model = keyboard.nextLine();
System.out.print("Enter the color of the car: ");
color = keyboard.nextLine();
System.out.print("Enter the lisence number of the car: ");
licenseNumber = keyboard.nextDouble();
System.out.print("Enter the minutes that the car was parked ");
minutesParked = keyboard.nextDouble();
}
}
import java.util.Scanner;
public class parkingMeter
{
public static void main(String[] args)
{
double minutesPurchased;
Scanner keyboard = new Scanner (System.in);
System.out.print("Enter the amount of minutes purchased: ");
minutesPurchased = keyboard.nextDouble();
}
}
class parkingTicket // I know this class is wrong, it is where I am confused... I attempted to
// use a similar class that was used in a previous program i think it
//confused me more...
{
private parkedCar questionedCar = null;
private policeOfficer officerOnDuty =null;
public parkingTicket ()
{
questionedCar = new parkedCar();
officerOnDuty = new policeOfficer();
}
public parkingTicket (parkedCar qCar, policeOfficer oOd)
{
questionedCar = qCar;
officerOnDuty = oOd;
}
public void set(parkedCar qCar, policeOfficer oOd)
{
questionedCar = qCar;
officerOnDuty = oOd;
}
public parkedCar getCar()
{
return questionedCar;
}
public policeOfficer getOfficer()
{
return officerOnDuty;
}
public String toString()
{
String str = "Questioned Car: " + questionedCar
+ "\nOfficer: " + officerOnDuty;
return str;
}
}
import java.util.Scanner;
public class policeOfficer
{
public static void main (String [] args)
{
String officerName;
double badgeNumber;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the officer's name: ");
officerName = keyboard.nextLine();
System.out.print("Enter the officer's badge number: ");
badgeNumber = keyboard.nextDouble();
}
}