There is an object, Cars, which is defined as,
class Cars{
String make;
String model;
String year;
....
}
Couple of restriction on the Object:
make, model and year can take any value.
there can't be two objects with the same set of attributes. For instance, there can't be a
car1 = { make : "Audi", model : "A6", year : "2008" }and acar2 = { make : "Audi", model : "A6", year : "2008"}
Let's say I talk to a service which gives me a list of all the car objects. I have an input (make,model,year). My job is to pick the car object from the list(returned by service). I should do so such that I will pick the object which matches as many attributes as possible.
Let me give an example. Lets suppose I get list of 5 cars from the service,
car1 = { make : "", model : "A6", year : "2008" }
car2 = { make : "Audi", model : "", year : "2008" }
car3 = { make : "Audi", model : "A6", year : "" }
car4 = { make : "", model : "", year : "" }
car5 = { make : "BMW", model : "M3", year : "2009" }
If my input is
{make : "Audi", model : "A6", year : "2008"}
I should be able to pick just one car from the list. If same number of parameters match, I should give preference in the order make > model > year. In the above case, I should pick car3.
Also if my input is
{ make : "Mercedes", model : "C300", year : "2008" }
I should pick car4 = { make : "", model : "", year : "" } (The generic one)
Any suggestions on solving this issue and/or pseudo-code?
{make: 'Audi', model: '', year: ''}and one with{make : "", model : "A6", year : "2008"}?