#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    9
    Rep Power
    0

    Help With Assignment Please


    1. Parking Ticket Simulator
    For this question you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes:

    The ParkedCar Class: This class should simulate a parked car. The car has a make, model, color, license number.
    The ParkingMeter Class: This class should simulate a parking meter. The class has two parameters the number of minutes of parking time that has been purchased; if the parking meter is expired, the number of minutes by which the purchased time has exceeded. (Normally parking meters just indicate whether the parking meter has expired, but for this example, assume that the parking meter is sophisticated enough to indicate the exceeded time).
    The ParkingTicket Class: This class should simulate a parking ticket. The class should report
    - the make, model, color and license number of the illegally parked car.
    - the amount of 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 of an hour that the car is illegally parked.
    - 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
    - has the officers name and badge number
    - examines the parking meter object and determines whether the cars time has expired
    - Issues a parking ticket (generates a ParkingTicket object) if the cars time has expired.
    Include appropriate instance variables and appropriate methods in each class.

    Write a program that demonstrates how these classes collaborate.

    /over

    This is wat i have so far

    //parked car class
    public class ParkedCar
    {
    private String make; // Car's make
    private String model; // Car's model
    private String color; // Car's color
    private String licenseNumber; // Car's alphanumeric license number
    public int minutes; // Minutes parked

    //@param prkcarmake The parked car's make.@param prkcarmodel The parked car's model.@param prkcarcolor The parked car's color.@param prkcarliscnumber The parked car's license plate number.@param prkcarminutes The number of minutes that the car has been parked.
    */

    public ParkedCar(String prkcarmake, String prkcarmodel, String prkcarcolor, String prkcarliscnumber, int prkcarminutes)
    {
    make = prkcarmake;
    model = prkcarmodel;
    color = prkcarcolor;
    licenseNumber = prkcarliscnumber;
    minutes = prkcarminutes;
    }

    //@param prkcarmake The parked car's make.@param prkcarmodel The parked car's model.@param prkcarcolor The parked car's color.@param prkcarliscnumber The parked car's license plate number.@param prkcarminutes The number of minutes that the car has been parked.


    public void set(String prkcarmake, String prkcarmodel, String prkcarcolor, String prkcarliscnumber, int prkcarminutes)
    {
    make = prkcarmake;
    model = prkcarmodel;
    color = prkcarcolor;
    licenseNumber = prkcarliscnumber;
    minutes = prkcarminutes;
    }



    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()
    {
    // Create a string representing the object.
    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 the string.
    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 parkmetminspurchased)
    {
    minutesPurchased = parkmetminspurchased;
    }

    //The set method sets a value for each field.@param Minutes of parking time purchased.


    public void set(int parkmetminspurchased)
    {
    minutesPurchased = parkmetminspurchased;
    }

    //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; // The amount of the 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(o);

    this.fine = fine;
    }



    //toString method @return A string containing the parking ticket information.


    public String toString()
    {
    // Create a string representing the object.
    String str = "Illegally parked car info: " + parkedcar +"\nParking meter info:" + parkingmeter +"\nAmount of the fine...: " + fine +"\nPolice officer info: " + policeofficer;

    // Return the string.
    return str;
    }
    }

    public class PoliceOfficer
    {
    private String name; // Name
    private int badgeNumber; // Badge number
    private ParkedCar parkedcar; // Initialize "parkedcar" object to be copied
    private ParkingMeter parkingmeter; // Initialize "parkingmeter" object to be copied
    private ParkingTicket parkingticket; //
    public double fine = 0; //

    //This constructor initializes the name and badgeNumber fields.@param poloffname The police officer's name. @param pobnumber The police officer's badge number.


    public PoliceOfficer(String poloffname, int pobnumber, ParkedCar pcar, ParkingMeter pmeter)
    {
    name = poloffname;
    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 poloffname The police officer's name.@param pobnumber The police officer's badge number.


    public void set(String poloffname, int pobnumber)
    {
    name = poloffname;
    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);
    }
    }


    public class Demo
    {
    public static void main (String[ ] args)
    {
    // Create a ParkedCar object, passing arguments to the constructor.
    ParkedCar myParkedCar = new ParkedCar("Mercedes", "Nissan", "White", "BMW", 48);

    // Create a ParkingMeter object, passing arguments to the constructor.
    ParkingMeter myParkingMeter = new ParkingMeter(48);

    // Create a ParkedCar object.
    ParkedCar secondParkedCar = new ParkedCar("Mercedes", "Nissan", "White", "BMW", 48);

    // Create a ParkingMeter object.
    ParkingMeter secondParkingMeter = new ParkingMeter(60);

    // Create a PoliceOfficer object.
    PoliceOfficer myPoliceOfficer = new PoliceOfficer("John Doe", 1337, myParkedCar, myParkingMeter);

    // Create a PoliceOfficer object.
    PoliceOfficer secondPoliceOfficer = new PoliceOfficer("John Doe", 1337, secondParkedCar, secondParkingMeter);

    //
    myPoliceOfficer.inspectParkedCar();

    ParkingTicket myParkingTicket = new ParkingTicket(myPoliceOfficer.fine, myParkedCar, myParkingMeter);
    myParkingTicket.toString();

    myParkedCar.toString();
    //
    secondPoliceOfficer.checkMeter(secondParkedCar, secondParkingMeter);
    }//end main
    }//end class
    -------------------------------------------
    now when i run it everyhtign is fine except there is no output
    and i recive 3 errors in the demo
    cannot find symbol variable o
    " " " " pcar


    greatly appreciated thanks
  2. #2
  3. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5054
    cannot find symbol
    You get that error when the compiler doesn't recognize something you typed. Typical causes are misspelled words and trying to use variables that haven't been declared in scope. The error message will tell you the line in which the error occurs. Look at that line and try to figure out why the compiler is asking you, "What are you talking about?"

    ~
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    9
    Rep Power
    0
    thankyou, i have been looking for the last 15 minutes and cant seem to see where i went wrong..
  6. #4
  7. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5054
    thankyou, i have been looking for the last 15 minutes and cant seem to see where i went wrong..
    Look at the specified line number in the class specified in the error message. That's your first hint. The second hint the compiler gives you is that it doesn't recognize the symbol 'o'. That should tell you that you're trying to use a variable that hasn't been declared in that scope.

    [EDIT] A quick scan of your sample code reveals the following problem:
    Java Code:
    // Create a new PoliceOfficer object, passing
    // pofficer as an argument to the copy constructor.
    policeofficer = new PoliceOfficer(o); // <-- I have to ask, too. What's 'o'?


    Follow this troubleshooting example for the remaining errors.

    ~
    Last edited by Yawmark; February 9th, 2009 at 08:31 PM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

IMN logo majestic logo threadwatch logo seochat tools logo