Reputation: 427
I just started an Object Orientated Programming class. I'm trying to write a program that adds a Customer
to a System
by giving name and age parameters, but duplicates are not allowed.
If I were writing this Java code normally, I would simply create a class named Customer
with name and age instance variables with a method called new()
which would create a new customer.
But since this isn't a list or anything, instead simply adding a Customer
to a System
, where do I write the method to not allow duplicates?
Upvotes: 1
Views: 76
Reputation: 82
Create field in System
or make System
extend Set
and override equals()
function in Customer
class to compare fields that can't be duplicates.
Upvotes: 1