I am learning Java in the course of an intro CS class, so I not very well versed in this language and I apologize in advance if I confuse some of the terms, though I did my best to use them accurately.
For this a problem in this class I am taking, I need to design three classes that work together, but there is a certain aspect of it that I don't understand.
These are the three classes that I have to design and the parts of them that are relevant to my question:
Has a boolean field called parkedLegally //True if parked legally, false if parked illegally
Has a string field called officerName //Contains the officer's name, like "Bob Smith"
Has a method called evaluateCar //Accepts a Car object as a parameter and determines if the car needs to be fined based on its parkedLegally value. If, and ONLY IF, it is to receive a fine, a Ticket type object is to be generated. If no fine is to be assessed, a Ticket object is NOT generated.
Has a double field called fineAmount //The amount of the fine, calculated by another method but not important to my issue
Since I don't know how many Car objects a PoliceOfficer will be asked to evaluate, let alone whether those Car objects will be parked illegally or not, I can't know in advance how many ticket objects need to be created. Also, since there may be more than one ticket, they have to have unique names. Therefore, I wanted to write code so that if a ticket needs to be generated, the evaluateCar method creates a new Ticket object each time it is called and determines that a fine needs to be issued, and gives it a procedurally generated name like bobSmithTicket1, bobSmithTicket2, bobSmithTicket3... etc.
What I don't understand is how to make the evaluateCar method create a Ticket object only under the proper circumstances, and to automatically assign a unique name to a Ticket. I can't seem to stick a string or anything like that in the area where the variable name would go in a declaration, so I can't generate new and uniquely identified Ticket objects. I have tried to look around and, as far as I can tell from my research, creating new objects after a Java program is compiled seems to be impossible. However, since the book I am working from asked me to do this I thought I would ask my specific question here just in case. Also, it would seem to be a huge limitation not to be able to create new instances of objects while a program was running. For instance, how would you make any program in java that required some number of objects but you couldn't know that number in advance (like this very problem, where I don't know how many tickets the user will need to write)?
Thanks for your help!