Ok, so you were able to post your homework, but how about explaining what the problem is you're having?
Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
For the first error, you're either using a constructor that does not exist, or you didn't properly import the class.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
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);
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
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.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
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.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
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.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711