I’m designing a simple car rental system and was wondering whether I was using good practice for the design. Basically, I have a showroom arraylist, which stores all rental cars (new objects). Inside each car object is an arraylist for the availability of that car for that month. The availability comprises of 31 values (corresponding to each day in that month), either 0 or 1 (available). They are initially set to 1 until a car is booked for that day. Is there another way of incorporating availability?
ArrayList<Car> showroom = new ArrayList<Car>();
ArrayList<Integer> Available1 = new ArrayList<Integer>();
ArrayList<Integer> Available2 = new ArrayList<Integer>();
setAllDatesAvailable(Available1);
setAllDatesAvailable(Available2);
Car number1 = new Car(objectitems, ... , Available1);
showroom.add(number1);
Car number2 = new Car(objectitems, ... , Available2);
showroom.add(number2);
//booking process
setAllDatesAvailable(ArrayList Array) {
for (int i = 0; i < 31; i++) {
Array.add(1);
}
NB:
- i’m not worried about timestamps, assume that the car is booked for
the whole day - assume that the system is only for a single month of 31 days
Here are some improvements that I would suggest for your code: –
First, follow Java Naming Conventions. Variable name should start with lowercase letters.
Available->available, or even better,availableDatesto match the purpose of yourListAlways use Generic Type collections.
to:
Use
Interfaceas your Reference types. You should declare your list as: –Same thing also in the formal parameters in your methods, as shown in comment by @Alex.
Choose meaningful name for your variables.
change it to: –
As far as possible, try to name your
formalparameters same as of youractualparameters.should better be declared as: –
After all these changes, you can look forward to improvise the functionality of your code, which @DNA has very nicely written in his answer.