Adewole Adebayo wrote:[code=java]when a customer enter his/her details the application request the customer to enter car details which in turn is saved in the HashMap<key, value>. when the customer enter details a car space number is assigned to the customer after which the application prompt if the user wants to enter another car details or as an admin( can view or delete customer details), the challenge is when the user select option 1 to enter car details after successfully adding details and car space assigned it overwrites the previous details. how can it be corrected?
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:I am not sure what you are asking. Please clarify: you want to implement a version/change history?
Adewole Adebayo wrote:[code=java]when a customer enter his/her details the application request the customer to enter car details which in turn is saved in the HashMap<key, value>. when the customer enter details a car space number is assigned to the customer after which the application prompt if the user wants to enter another car details or as an admin( can view or delete customer details), the challenge is when the user select option 1 to enter car details after successfully adding details and car space assigned it overwrites the previous details. how can it be corrected?
Dave Tolls wrote:The 'details' variable looks like a Map?
Where is that Map stored?
That is, you need somewhere to store multiple details.
Currently you seem to have just the one, which you are overwriting each time the user enters some new details.
Dave Tolls wrote:But as far as I can see you only have the one Map.
And that map shows no sign of anything that associates it with a particular customer (at least from the code as shown).
To be honest, that should almost certainly be a class that represents that data, say CarDetails. You could then have a List<CarDetails> which lists the cars booked in.
Campbell Ritchie wrote:I think maybe you should explain a bit more about the assignment.
How many Cars do you have and how are you recording them? Do the details refer to a car, or to a car used by a customer? If your properties Map is a field of the Car class, how is it declared and populated?
Campbell Ritchie wrote:Instance field or static field?
Dave Tolls wrote:I think you're going to have to detach at least some of the UI bits (that is your prompts etc) from the Car class itself (I would detach all of them, but I have no idea of timescales here).
The issue you have is you have a single Car in which you prompt the user for the details, but you also have that class prompting if the user wants to enter another Car...that part has to be outside of Car.
A single Car should not care whether there are any other Cars.
It should also not care if there are any other spaces.
A CarPark class should handle that side of things.
Note that I have no idea what your actual requirements are, so that there is just an example.
New rule: no elephants at the chess tournament. Tiny ads are still okay.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|