• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

how to keep existing record entered by user intact while new details is entered when requested

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That is some portion of the code, 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?
 
Rancher
Posts: 962
23
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Adewole Adebayo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whenever the method (carDetails) is invoked after a customer authenticates his/her login, the customer enters his/her car details which will be stored in LinkedHasMap<String, String> details = new LinkedHasMap<String, String>() for the particular customer... in the same method (carDetails) a switch statement is provided to ask if the customer wishes to enter another car details (assuming it's another customer this time), if the details entered by the later customer is entered and is stored in the Map it overwrites the previous data. how can I make the previously added details in the map still be intact if new details are entered?




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
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Adewole Adebayo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

this is the complete code for the class Car in the package parkingsystem


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.

 
Adewole Adebayo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so looking at the code, can you give me a snippet on how to make it keep previous records entered by customers and for 20 customers maximum?
it's a semester 2 project... Thanks in advance


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.

 
Marshal
Posts: 73246
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Adewole Adebayo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cars? the map is a field in the car class which keeps track of car details entered by customers via the method carDetails(). yes! am keeping record of car details entered by each customer.


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
Marshal
Posts: 73246
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instance field or static field?
 
Adewole Adebayo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instance field.

Campbell Ritchie wrote:Instance field or static field?

 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Adewole Adebayo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello your idea to split the car class I tried to figure out what you meant so fortunately for me I saw a similar project which I went through the code and I was able to implement the split process you mentioned.. below is the new modification and the class I added.. Thank you Mr Dave



code for CarHashDetails



Car class


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.

 
Marshal
Posts: 8010
563
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, but there are lots of issues with that class.

1. All those comments are useless, just duplicating the code and making it difficult to read - consider removing all.
2. All class variables need to be with private access modifier. There are some exceptions, but probably not in your case.
3. Your methods are the way too long. They do all sort of other things than their names suggest they are meant to do.

I think you need to resist from writing more lines of code until you get your project logic clear and written in a form of pseudo code. Write down on a piece of paper (I always start from there) step by step, what you need to do.

Read the tutorial WhatNotHow before you move on.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic