"no suitable constructor found & cannot find symbol."
Any advice would be greatly appreciated, thank you again.
The guide lines to my problem are:
The ParkedCar Class: This class should simulate a parked car. The class's responsibilities are as follows:
- To know the car's make, model, color, license number, and the number of minutes that the car has been parked.
The ParkingMeter Class: This class should simulate a parking meter. The class's only responsibility is as follows:
- To know the number of minutes of parking time that has been purchased.
The ParkingTicket Class: This class should simulate a parking ticket. The class's responsibilities are as follows:
- To report the make, model, color, and license number of the illegally parked car
- To report the amount of the fine, which is $25 for the first hour or part of an hour that the car is illegally parked, plus $10 for every additional hour or part hour that the car is illegally parked, plus $l0 for every additional hour or part of an hour that the car is illegally parked
- To report the name and badge number of the police officer issuing the ticket
The PoliceOfficer Class: This class should simulate a police officer inspecting parked cars. The class's responsibilities are as follows:
- To know the police officer's name and badge number
- To examine a ParkedCar 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
Here is the code I have for the 4 classes:
public class ParkedCar
{
private String make;
private String model;
private String color;
private String licenseNumber;
public int minutes;
/**
This constructor initializes the make, model, color, licenseNumber, and minutes fields.
@param pcmake The parked car's make.
@param pcmodel The parked car's model.
@param pccolor The parked car's color.
@param pclnumber The parked car's license plate number.
@param pcminutes The number of minutes that the car has been parked.
*/
public ParkedCar(String pcmake, String pcmodel, String pccolor, String pclnumber, int pcminutes)
{
make = pcmake;
model = pcmodel;
color = pccolor;
licenseNumber = pclnumber;
minutes = pcminutes;
}
/** The set method sets a value for each field.
@param pcmake The parked car's make.
@param pcmodel The parked car's model.
@param pccolor The parked car's color.
@param pclnumber The parked car's license plate number.
@param pcminutes The number of minutes that the car has been parked.
*/
public void set(String pcmake, String pcmodel, String pccolor, String pclnumber, int pcminutes)
{
make = pcmake;
model = pcmodel;
color = pccolor;
licenseNumber = pclnumber;
minutes = pcminutes;
}
/** The copy constructor initializes the object
as a copy of another ParkedCar object.
@param object2 The object to copy.
*/
public ParkedCar(ParkedCar object2)
{
make = object2.make;
model = object2.model;
color = object2.color;
licenseNumber = object2.licenseNumber;
minutes = object2.minutes;
}
/**
toString method
@return A string containing the parked car information.
*/
public String toString()
{
String str = "Parked car's make.....................: " + make +
"\nParked car's model..................: " + model +
"\nParked car's color..................: " + color +
"\nParked car's license plate number...: " + licenseNumber +
"\nMinutes that the car has been parked: " + minutes;
return str;
}
}
public class ParkingMeter
{
public int minutesPurchased; // The number of minutes of parking time that has been purchased
/**
This constructor initializes the minutesPurchased field.
@param Minutes of parking time purchased.
*/
public ParkingMeter(int pmmpurchased)
{
minutesPurchased = pmmpurchased;
}
/**
The set method sets a value for each field.
@param Minutes of parking time purchased.
*/
public void set(int pmmpurchased)
{
minutesPurchased = pmmpurchased;
}
/** The copy constructor initializes the object
as a copy of another ParkingMeter object.
@param object2 The object to copy.
*/
public ParkingMeter(ParkingMeter object2)
{
minutesPurchased = object2.minutesPurchased;
}
/**
getMinutesPurchased method
@return The number of minutes of parking time that has been purchased.
*/
public int getMintuesPurchased()
{
return minutesPurchased;
}
}
public class ParkingTicket
{
private double fine;
private ParkedCar parkedcar;
private ParkingMeter parkingmeter;
private PoliceOfficer policeofficer;
/**
This constructor initializes the parkedcar, parkingmeter, and policeofficer fields.
@param parkedcar
@param parkingmeter
@param policeofficer
*/
public ParkingTicket(double fine, ParkedCar pcar, ParkingMeter pmeter)
{
// Create a new ParkedCar object, passing
// pcar as an argument to the copy constructor.
parkedcar = new ParkedCar(pcar);
// Create a new ParkingMeter object, passing
// pmeter as an argument to the copy constructor.
parkingmeter = new ParkingMeter(pmeter);
// Create a new PoliceOfficer object, passing
// pofficer as an argument to the copy constructor.
//policeofficer = new PoliceOfficer(pofficer);
this.fine = fine;
}
/**
toString method
@return A string containing the parking ticket information.
*/
public String toString()
{
String str = "Illegally parked car info: " + parkedcar +
"\nParking meter info:" + parkingmeter +
"\nAmount of the fine...: " + fine;
//"\nPolice officer info: " + policeofficer;
return str;
}
}
public class PoliceOfficer
{
private String name;
private int badgeNumber;
private ParkedCar parkedcar;
private ParkingMeter parkingmeter;
private ParkingTicket parkingticket;
public double fine = 0;
/**
This constructor initializes the name and badgeNumber fields.
@param poname The police officer's name.
@param pobnumber The police officer's badge number.
*/
public PoliceOfficer(String poname, int pobnumber, ParkedCar pcar, ParkingMeter pmeter)
{
name = poname;
badgeNumber = pobnumber;
// Create a new ParkedCar object, passing
// pcar as an argument to the copy constructor.
parkedcar = new ParkedCar(pcar);
// Create a new ParkingMeter object, passing
// pmeter as an argument to the copy constructor.
parkingmeter = new ParkingMeter(pmeter);
}
/** The set method sets a value for each field.
@param poname The police officer's name.
@param pobnumber The police officer's badge number.
*/
public void set(String poname, int pobnumber)
{
name = poname;
badgeNumber = pobnumber;
}
/** The copy constructor initializes the object
as a copy of another PoliceOfficer object.
@param object2 The object to copy.
*/
public PoliceOfficer(PoliceOfficer object2)
{
name = object2.name;
badgeNumber = object2.badgeNumber;
// Create a new ParkedCar object, passing
// pcar as an argument to the copy constructor.
//parkedcar = new ParkedCar(pcar);
//Create a new ParkedCar object.
//parkedcar = new ParkedCar(pcar);
//Create a ParkingMeter object.
//parkingmeter = new ParkingMeter(pmeter);
}
public ParkedCar getParkedCar()
{
// Return a copy of the ParkedCar object.
return new ParkedCar(parkedcar);
}
public ParkingMeter getParkingMeter()
{
// Return a copy of the ParkingMeter object.
return new ParkingMeter(parkingmeter);
}
public void inspectParkedCar()
{
// Determine whether the car is illegally parked.
if (parkedcar.minutes > parkingmeter.minutesPurchased)
// Determine the amount of the fine.
if (parkedcar.minutes - parkingmeter.minutesPurchased <= 60)
fine = 25;
else
fine = 25 + (10 * ((parkedcar.minutes - parkingmeter.minutesPurchased) / 60));
// Create a ParkingTicket object, passing
// 3 objects as arguments to the constructor.
parkingticket = new ParkingTicket(fine, parkedcar, parkingmeter);
}
}
And the Demo for running the code.
public class TestParkingTicket
{
public static void main(String[] args)
{
// This 1986 Ford was parked for 85 minutes
ParkedCar car = new ParkedCar("Ford", "1986", "Grey",
"BAC4455", 85);
// The meter had 30 minutes on it
ParkingMeter meter = new ParkingMeter(30);
PoliceOfficer officer = new PoliceOfficer("John Doe",
"9932");
// The officer is on patrol and sees the parked car
// and the meter.
// If the car was parked for a longer time than was
// on the meter, then the "patrol" method will
// issue a ticket.
// If there was enough time on the meter to cover the
// time the car was parked, then no ticket is
// issued (i.e., a null reference is returned).
ParkingTicket ticket = officer.patrol(car, meter);
// If no ticket was issued, then "ticket" is null
if (ticket == null)
System.out.println("No crimes committed!");
else
{
System.out.println("TICKET ISSUED: ");
System.out.println(ticket);
}
}
}

New Topic/Question
Reply



MultiQuote





|