I had been creating 5 files and I kept hitting the wall. Hope that you will be able to help me pinpoint the problems. (I am not an programmer by the way.) I had been researching for more details on those problems, no luck.

Enclosed are 5 files that I had created. Hope to hear from you soon because I need to turn them in next week as an final project at my college.

The ParkCar class: This class show simulate a parked car. The class' responsibilities are

  • 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' responsibilities are

  • To know the number of minutes of parking times that has been purchased.

The ParkingTicket class: This class should simulate a parking ticket. The class' responsibilities are

  • 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 our 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 plice officer inspecting parked cars. The class' responsibilities are

  • 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.
Attachments
/*
	William Raby
	5/7/09
	CSP 026A Final Programming Project
	
	MeterTest Class
*/

import java.util.*;

public class MeterTest
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		
		ParkedCar car = new ParkedCar("Honda", "Civic", "Black", "ZZZ111", 54);
		ParkingMeter meter = new ParkingMeter(50);
		PoliceOfficer cop = new PoliceOfficer("Raby", 1234, car, meter);
		cop.inspectParkedCar();
		ParkingTicket ticket = new ParkingTicket(cop.fine, car, meter);
		ParkigTicket ticket = cop.ticket(car, meter);
		{
			if(myticket != null)
				System.out.println(ticket);
			else
				System.out.println("No Ticket Issued");
		}
	}
}
/*
	William Raby
	5/7/09
	CSP 026A Final Programming Project
	
	ParkedCar Class
*/

public class ParkedCar
{
	private String make;
	private String model;
	private String color;
	private String licenseNumber;
	private int minutesParked;
	
	public ParkedCar()
	{
		String make = "";
		String model = "";
		String color = "";
		String licenseNumber = "";
		minutesParked = 0;
	}
	
	public ParkedCar(String mk, String mod, String col, String ln, int mp)
	{
		make = mk;
		model = mod;
		color = col;
		licenseNumber = ln;
		minutesParked = mp;
	}
	
	public ParkedCar(ParkedCar original)
	{
		this.make = original.make;
		this.model = original.model;
		this.color = original.color;
		this.licenseNumber = original.licenseNumber;
		this.minutesParked = original.minutesParked;
	}
	
	public void setAll(String mk, String mod, String col, String ln, int mp)
	{
		make = mk;
		model = mod;
		color = col;
		licenseNumber = ln;
		minutesParked = mp;
	}
	
	public int getParkedMinutes()
	{
		int carPark;
		carPark = minutesParked;
		return carPark;
	}
	
	public String toString()
	{
		String state = "\nMake: " + make + "\nModel: " + model + "\nColor: " + color + "\nLicense Number: " + licenseNumber + "\nMinutes Parked: " + minutesParked;
		return state;
	}
	
	public boolean equals(ParkedCar car)
	{
		if (this.make.equals(car.make) && this.model.equals(car.model) && this.color.equals(car.color) && this.licenseNumber.equals(car.licenseNumber) && this.minutesParked==(car.minutesParked))
			return true;
		else
			return false;
	}
}
/*
	William Raby
	5/7/09
	CSP 026A Final Programming Project
	
	ParkingMeter Class
*/

public class ParkingMeter
{
	private int minutesPurchased;
	
	public ParkingMeter()
	{
		minutesPurchased = 0;
	}

	public ParkingMeter(int mp)
	{
		minutesPurchased = mp;
	}
	
	public ParkingMeter(ParkingMeter original)
	{
		this.minutesPurchased = original.minutesPurchased;
	}
	
	public void set(int mp)
	{
		minutesPurchased = mp;
	}
	
	public int getPurchasedMinutes()
	{
		int parkMeter;
		parkMeter = minutesPurchased;
		return parkMeter;
	}
	
	public String toString()
	{
		String state = "\nMinutes Purchased: " + minutesPurchased;
		return state;
	}

	public boolean equals(ParkingMeter meter)
	{
		if (this.minutesPurchased==(meter.minutesPurchased))
			return true;
		else
			return false;
	}
}
/*
	William Raby
	5/7/09
	CSP 026A Final Programming Project
	
	ParkingTicket Class
*/

public class ParkingTicket
{
	private ParkedCar car = new ParkedCar();
	private ParkingMeter meter = new ParkingMeter(0);
	private PoliceOfficer cop = new PoliceOfficer();
	private double fine;
	private int mins;

	public ParkingTicket()
	{
		car = new ParkedCar();
		meter = new ParkingMeter();
		cop = new PoliceOfficer();
	}

	public ParkingTicket(double fine, ParkedCar pc, ParkingMeter pm, PoliceOfficer po)
	{
		car = new ParkedCar(pc);
		meter = new ParkingMeter(pm);
		cop = new PoliceOfficer(po);
	}

	public ParkingTicket(ParkingTicket original)
	{
		this.car = new ParkedCar(original.car);
		this.meter = new ParkingMeter(original.meter);
		this.cop = new PoliceOfficer(original.cop);
		this.fine = fine;
	}
	
	public void inspectParkedCar(int cm, int pm, int mins)
	{
		cm = car.getParkedMinutes();
		pm = meter.getPurchasedMinutes();
		mins = cm - pm;
		if (mins < 0)
			if (mins > 0 && mins <= 60)
				fine = 25;
			else
				fine = 25 + ((10 * mins) / 60);
		ParkingTicket ticket= new ParkingTicket(fine, car, meter);
	}

	public String toString()
	{
		String state = "\nIllegally parked car information: " + car.toString() + "\nParking meter information: " + meter.toString() +
							"\nPolice Officer informtion: " + cop.toString() + "\nAmount of the fine; " + fine;
		return state;
	}

	public boolean equals(ParkingTicket ticket)
	{
		if (this.car==(ticket.car) && this.meter==(ticket.meter) && this.cop==(ticket.cop))
			return true;
		else
			return false;
	}
}
/*
	William Raby
	5/7/09
	CSP 026A Final Programming Project
	
	PoliceOfficer Class
*/

public class PoliceOfficer
{
	private String officerName;
	private int badgeNumber;
	private ParkedCar car;
	private ParkingMeter meter;
	private ParkingTicket ticket;

	public PoliceOfficer()
	{
		officerName = "";
		badgeNumber = 0;
		car = new ParkedCar();
		meter = new ParkingMeter();
		ticket = new ParkingTicket();
	}
	
	public PoliceOfficer(String on, int bn, ParkedCar pc, ParkingMeter pm, ParkingTicket ticket)
	{
		officerName = on;
		badgeNumber = bn;
		car = new ParkedCar(pc);
		meter = new ParkingMeter(pm);
		ticket = new ParkingTicket(ticket);
	}

	public PoliceOfficer(PoliceOfficer original)
	{
		this.officerName = original.officerName;
		this.badgeNumber = original.badgeNumber;
		this.car = new ParkedCar(original.car);
		this.meter = new ParkingMeter(meter);
		this.ticket = new ParkingTicket(ticket);
	}

	public void setAll(String on, int bn, ParkedCar pc, ParkingMeter pm)
	{
		officerName = on;
		badgeNumber = bn;
		car = new ParkedCar(pc);
		meter = new ParkingMeter(pm);
		ticket = new ParkingTicket(ticket);
	}

	public ParkedCar getParkedCar()
	{
		return new ParkedCar(car);
	}

	public ParkingMeter getParkingMeter()
	{
		return new ParkingMeter(meter);
	}
	
	public ParkingTicket getParkingTicket()
	{
		return new ParkingTicket(ticket);
	}

	public boolean checkCar(ParkedCar car, ParkingMeter meter)
	{
		if(car.getParkedMinutes() > meter.getPurchasedMinutes())
			return true;
		else
			return false;
	}
	
	public ParkingTicket ticket(ParkedCar car, ParkingMeter meter)
	{
		if(checkCar(car, meter) == true)
			return new ParkingTicket(ticket);
		else
			return null;
	}
	
	public String toString()
	{
		String state = "\nOfficer Name: " + officerName + "\nBadge Number: " + badgeNumber + "\nTicket Issued: " + ticket;
		return state;
	}
	
	public boolean equals(PoliceOfficer cop)
	{
	if (this.officerName.equals(cop.officerName) && this.badgeNumber==(cop.badgeNumber) && this.ticket==(cop.ticket))
		return true;
	else
		return false; 
	}
}

Ok, so you were able to post your homework, but how about explaining what the problem is you're having?

Ok, so you were able to post your homework, but how about explaining what the problem is you're having?

Updated: In the ParkingMeter, I put "//" in this line which gave me an less error.

public void inspectParkedCar(int cm, int pm, int mins)
	{
		cm = car.getParkedMinutes();
		pm = meter.getPurchasedMinutes();
		mins = cm - pm;
		if (mins < 0)
			if (mins > 0 && mins <= 60)
				fine = 25;
			else
				fine = 25 + ((10 * mins) / 60);
		//ParkingTicket ticket= ParkingTicket(fine, car, meter);
	}

Copied and pasted from jGRASP:

MeterTest.java:19: cannot find symbol
symbol  : constructor PoliceOfficer(java.lang.String,int,ParkedCar,ParkingMeter)
location: class PoliceOfficer
		PoliceOfficer cop = new PoliceOfficer("Raby", 1234, car, meter);
		                    ^
MeterTest.java:20: cannot find symbol
symbol  : method inspectParkedCar()
location: class PoliceOfficer
		cop.inspectParkedCar();
		   ^
MeterTest.java:21: cannot find symbol
symbol  : variable fine
location: class PoliceOfficer
		ParkingTicket ticket = new ParkingTicket(cop.fine, car, meter);
		                                            ^
MeterTest.java:21: internal error; cannot instantiate ParkingTicket.<init> at ParkingTicket to ()
		ParkingTicket ticket = new ParkingTicket(cop.fine, car, meter);
		                       ^
MeterTest.java:22: cannot find symbol
symbol  : class ParkigTicket
location: class MeterTest
		ParkigTicket ticket = cop.ticket(car, meter);
		^
MeterTest.java:22: ticket is already defined in main(java.lang.String[])
		ParkigTicket ticket = cop.ticket(car, meter);
		             ^
MeterTest.java:24: cannot find symbol
symbol  : variable myticket
location: class MeterTest
			if(myticket != null)
			   ^
7 errors

For the first error, you're either using a constructor that does not exist, or you didn't properly import the class.

How do I solve this problem?

How do I solve this problem?

Use a constructor that DOES exist or import the class. In your case, it's the former. Here are your constructors:

public PoliceOfficer()
	public PoliceOfficer(String on, int bn, ParkedCar pc, ParkingMeter pm, ParkingTicket ticket)
	public PoliceOfficer(PoliceOfficer original)

Here's your error:

MeterTest.java:19: cannot find symbol
symbol : constructor PoliceOfficer(java.lang.String,int,ParkedCar,ParkingMeter)
location: class PoliceOfficer
PoliceOfficer cop = new PoliceOfficer("Raby", 1234, car, meter);

None of your constructors take four arguments. The closest is this:

public PoliceOfficer(String on, int bn, ParkedCar pc, ParkingMeter pm, ParkingTicket ticket)

You do not pass it a ParkingTicket object. Hence the error.


The errors say exactly what's wrong and even point to exactly what's wrong. Read them carefully. Spelling counts.

MeterTest.java:22: cannot find symbol
symbol : class ParkigTicket
location: class MeterTest
ParkigTicket ticket = cop.ticket(car, meter);

I fixed some errors but still having problems... I looked at all objects and am still having problems.

Will it be easy for you if I post the classes instead attachments?

Will it be easy for you if I post the classes instead attachments?

It's not a bad idea to post a zip file with all the java files, and in addition you can post/describe any changes and current problems. If you post the zip file, it's a quick download, then we can unzip it as is and compile it rather than a whole bunch of cut and pastes and there's less to keep track of. Post the line itself as well as the error message and a description.

Sure... I had been changing some of classes... I think I am getting there now. Let me zip all 5 files and attach it here.

Please discard 5 files on my first post, I had changed some of them and updated problems. Here is a updated version of zipped, MeterTest.zip. Thank you for trying to help me out!

The new errors are:

----jGRASP exec: javac -g E:\Delta College\CSP 026A\Final Programming Project\MeterTest.java

MeterTest.java:19: cannot find symbol
symbol  : variable ticket
location: class MeterTest
		PoliceOfficer cop = new PoliceOfficer ("Raby", 1234, car, meter, ticket);		
		                                                                 ^
MeterTest.java:21: cannot find symbol
symbol  : method inspectParkedCar()
location: class PoliceOfficer
		cop.inspectParkedCar();
		   ^
MeterTest.java:22: cannot find symbol
symbol  : variable fine
location: class PoliceOfficer
		ParkingTicket ticket = new ParkingTicket (cop.fine, car, meter);
		                                             ^
MeterTest.java:22: internal error; cannot instantiate ParkingTicket.<init> at ParkingTicket to ()
		ParkingTicket ticket = new ParkingTicket (cop.fine, car, meter);
		                       ^
MeterTest.java:23: ticket is already defined in main(java.lang.String[])
		ParkingTicket ticket = cop.ticket(car, meter, cop);
		              ^
5 errors

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.
public class MeterTest
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		
		ParkedCar car = new ParkedCar ("Honda", "Civic", "Black", "ZZZ111", 54);
		ParkingMeter meter = new ParkingMeter (50);
		PoliceOfficer cop = new PoliceOfficer ("Raby", 1234, car, meter, ticket);		
				
		cop.inspectParkedCar();
		ParkingTicket ticket = new ParkingTicket (cop.fine, car, meter);
		ParkingTicket ticket = cop.ticket(car, meter, cop);
		{
			if(ticket != null)
				System.out.println(ticket);
			else
				System.out.println("No Ticket Issued");
		}
	}

Lines 12 and 13 - two objects with the same name are declared. You can't do that.

Line 9 - Why is this line BEFORE line 12? You can't use an object that you haven't declared yet in a function call. ticket doesn't exist until line 12. You can't use it in line 9.

Line 11 - There is no inspectParkedCar function in the PoliceOfficer class. There's a function by that name in ParkingTicket, but not PoliceOfficer.

Line 12 - There is no fine attribute in PoliceOfficer. fine is in ParkingTicket, not PoliceOfficer.


Again, read the error messages carefully.

Wow! I am getting confused! I am trying to understand what you are trying to explain, VernonDozier.

Wow! I am getting confused! I am trying to understand what you are trying to explain, VernonDozier.

You are going to be more specific. Pretend you are the compiler. You need to be able to figure out what every piece of code refers to. You are being told "look for this function in the PoliceOfficer class" and the function isn't there. You're not going to know what the author of the code intended. You have to TELL the compiler where to look and you can't tell it to look for something that doesn't exist.

I understood now, I had read the textbook and finally got it to work nicely now!

VernonDozier, thank you a million for helping me understand how those java works! I am still d'uh until final exam next week! LOL!

This question has already been answered. Start a new discussion instead.