Assessment Task

You have been tasked with creating a basic Car Rental System in Java. This system should be able to keep track of the availability of all the cars in a Rent-a-car business over the course of a year.

  • A Rent-a-car contains Cars
  • Cars have a make, a daily rate, an id and a calendar of availability.

A sample main method has been provided to test the code you write.

Each of the interfaces given should be implemented by you according to the instructions in this brief. You may not alter the interfaces in any way, with the only exception of the import for your custom packages. You must structure your code as described in this brief. All the files you have been given should remain in the given package. All the files you implement should be placed in the same given package called ooc.yoursolution.

Provided files

  • CarInterface.java - lists the method signatures of a Car.
  • RentACarInterface.java - lists the method signatures of a Rent-a-car business. Remember, a rent-a car contains cars.
  • BookingSystemInterface.java - defines the method signatures for a class which is in charge of creating rent-a-car business.
  • Driver.java - a main method for you to try your code out.
  • amilcar_rentals.txt - a text based file that includes the details of one Rent-a-car business. It has all details regarding the cars: make, daily rate and amount of cars of the specific model the business has.

Specific Requirements

You are required to implement three classes:

  • Car.java - implements the CarInterface.
  • RentACar.java - implements the RentACarInterface.
  • BookingSystem.java - implements the BookingSystemInterface.

You must implement all methods defined in the relevant interfaces, you may define additional helper methods if it makes your coding easier but this is not required.

You will also have to implement some attributes for some classes. Use the setters/getters defined in the interfaces to make an informed decision on the types/values of these attributes. Whether or not to include a constructor in your classes is at your discretion. Make an informed decision and on this and make sure to include a short justification as a comment.

In the main method, your will have to write the necessary code, to try out the program.

You must not change any of the method signatures, the interfaces, or the structure txt file.

You must put the files you write in the given package called ooc.yoursolution.

Text file structure:

amilcar_rentals // Rent-a-car business name
BMW:250:3 // Make BMW, €250 per day, there are 3 of them.
TOYOTA:200:8 // Make TOYOTA, €200 per day, there are 8 of them.
FORD:150:10 // Make FORD, 150 per day, there are 10 of them.
FIAT:75:15 // Make FIAT, €75 per day, there are 15 of them.
CHEVROLET:150:10 // Make CHEVROLET, €250 per day, there are 10 of them.

Starter Codes

CarInterface.java

package ooc.yoursolution;

import ooc.enums.Make;
import ooc.enums.Month;
import java.util.Map;

/**
* This is one of the interfaces you need to implement
*
* @author apont
*/
public interface CarInterface {

/**
* This method in in charge of creating the calendar of availability
* of the car for the whole year.
* The calendar should be a Map that uses the Month as the key,
* and an array of boolean as its associated value.
*
* @return Map of availability
*/
public Map< Month, boolean[] > createAvailability();

/**
* Getter method for the make of this car.
*
* @return the make of the car
*/
public Make getMake();

/**
* Sets the make of the car.
*
* @param make
*/
public void setMake(Make make);

/**
* Getter method for the rate of this car.
*
* @return rate of the car.
*/
public double getRate();

/**
* Sets the rate of the car.
*
* @param rate
*/
public void setRate(double rate);

/**
* Getter method for the availability calendar of this car.
*
* @return Map of availability
*/
public Map< Month, boolean[] > getAvailability();


/**
* Sets the availability calendar of the car.
*
* @param availability
*/
public void setAvailability(Map< Month, boolean[] > availability);

/**
* Getter method for the id of this car.
*
* @return
*/
public int getId();

/**
* Returns whether or not the car is available on the given month and day.
* Month is an Emum, day is an int within the limits of the number of days
* in a given month
*
* @param month Month being checked
* @param day date being checked
* @return true or false if it is available or not
*/
public boolean isAvailable(Month month, int day);

/**
* Book a room on the given month and day. To book a room its availability
* is changed to false on the given month and day.
* This should return true or false if this change is successfully made
*
* @param month month to book
* @param day date to book
* @return true or false if the booking is completed
*/
public boolean book(Month month, int day);
}

RentACarInterface.java

package ooc.yoursolution;

import ooc.enums.Make;
import ooc.enums.Month;
import java.util.List;

/**
*
* This is one of the interfaces you need to implement
*
*/
public interface RentACarInterface {

/**
* Return the full list of cars.
*
* @return List of cars
*/
public List< CarInterface > getCars();

/**
* Helper method to set all the cars with a list if we so wished
*
* @param cars List of cars
*/
public void setCars(List< CarInterface > cars);

/**
* Return the name of the Rent-a-car
*
* @return
*/
public String getName();

/**
* Set the name of the rent-a-car.
*
* @param name
*/
public void setName(String name);

/**
* Check through all cars in this hotel and see if there is continuous
* availability of any specific car. It is not enough to just have
* any car available for the length of stay, we need it to be in one
* specific car.
*
* @param month Month of proposed rent
* @param day Day of start of proposed rent
* @param make Make, what sort of car for the proposed rent
* @param lengthOfRent how long is the proposed rent for
*
* @return true or false is there availability for the proposed rent
*/
public boolean checkAvailability(Month month, int day, Make make, int lengthOfRent);

/**
* Assuming there is availability, get the id of a car that fits that
* availability
*
* @param month Month of proposed rent
* @param day Day of start of proposed rent
* @param make Make, what sort of car for the proposed rent
* @param lengthOfRent how long is the proposed rent for
* @return the id of a room that fits the bill
*/
public int getCarAvailable(Month month, int day, Make make, int lengthOfRent);

/**
* Book a car for the proposed rent. It should be one car for the full
* time. THERE IS NO NEED TO CONSIDER RENTALS THAT ROLL OVER TWO MONTHS
*
* @param month Month of proposed rent
* @param day Day of start of proposed rent
* @param make Make, what sort of car for the proposed rent
* @param lengthOfRent how long is the proposed rent for
* @return true or false has the room been booked
*/
public boolean bookCar(Month month, int day, Make make, int lengthOfRent);

/**
* How many cars are in the rent-a-car
*
* @return number of cars
*/
public int getNumberOfCars();
}

BookingSystemInterface.java

package ooc.yoursolution;

import java.io.BufferedReader;
import java.io.IOException;

/**
*
* This is one of the interfaces you need to implement
*
*/
public interface BookingSystemInterface {

/**
* This method reads in from the given bufferedReader object. This should be
* opening the text file with the data about number of cars and their
* makes. You may assume that the structure of this file is always the same.
*
* @param in instance of the buffered reader class that has open the file
* @return instance of the Rent-a-car class.
* @throws IOException
*/
public RentACarInterface setupRentACar(BufferedReader in) throws IOException;

}

Driver.java

package rentacar;

// This line will give you an error until you create the needed class.
import ooc.yoursolution.BookingSystem;

import ooc.yoursolution.BookingSystemInterface;
import ooc.yoursolution.RentACarInterface;
import ooc.enums.Make;
import ooc.enums.Month;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

// INCLUDE HERE THE LINK TO THE GIT REPOSITORY AS A COMMENT!!!!


// INCLUDE HERE THE FULL NAME AND STUDENT NUMBER OF BOTH TEAM MEMBERS
// AS A COMMENT!!!!



/**
*
* @author apont
*/
public class Driver {

/**
* Do not change the signature of the main method!
*
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {

BookingSystemInterface bookingSystem = new BookingSystem();

String file = "amilcar_rentals.txt";
BufferedReader in = new BufferedReader(new FileReader(file));

RentACarInterface rentACar = bookingSystem.setupRentACar(in);

// Get the name of the car rental
System.out.println(rentACar.getName());

// Print the number of cars in the rent-a-car
System.out.println(rentACar.getNumberOfCars());

// Check if there is a BMW car available for 5 days from the 1st
// of January
System.out.println(rentACar.checkAvailability(Month.JANUARY, 1, Make.BMW, 5));

// Get the id of the car available
System.out.println(rentACar.getCarAvailable(Month.JANUARY, 1, Make.BMW, 5));

// Try some bookings
System.out.println(rentACar.bookCar(Month.JANUARY, 1, Make.BMW, 5));
System.out.println(rentACar.bookCar(Month.JANUARY, 1, Make.BMW, 5));
System.out.println(rentACar.bookCar(Month.JANUARY, 1, Make.BMW, 5));
System.out.println(rentACar.bookCar(Month.JANUARY, 1, Make.BMW, 5));
System.out.println(rentACar.bookCar(Month.FEBRUARY, 3, Make.FIAT, 10));
System.out.println(rentACar.bookCar(Month.MARCH, 10, Make.FORD, 12));

}

}

amilcar_rentals.txt

amilcar_rentals
BMW:250:3
TOYOTA:200:8
FORD:150:10
FIAT:75:15
CHEVROLET:150:10
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.