Share on Google+Share on Google+

Car Rental Application in Java

In this section, we are going to create a Java application regarding Car renting, booking and checking the availability of vehicles.

Car Rental Application in Java

In this section, we are going to create a Java application regarding car renting, booking and checking the availability of vehicles. For this application we have stored some model names, their registration no, rent rate on the basis of per day, and the amount to deposit in the arraylist. Now, a user is allowed to enter the model name to rent. If model is available, a message will get appeared and asks the no of days for rent. After that, it will display details on Deposit,Daily Rate, and Total Cost and asks the user whether he/she want to proceed or not. If user wants to proceeds, user is allowed to enter name and IC no. After that, the receipt will get displayed including all the details.

Here is the code:

import java.util.*;

class Car {
	private String make;
	private String model;
	private String regNo;
	private int deposit;
	private int rate;

	public Car(String newMake, String newModel, String newRegNo,
			int newDeposit, int newRate) {
		make = newMake;
		model = newModel;
		regNo = newRegNo;
		deposit = newDeposit;
		rate = newRate;

	public String getMake() {
		return make;

	public String getModel() {
		return model;

	public String getRegNo() {
		return regNo;

	public int getDeposit() {
		return deposit;

	public int getRate() {
		return rate;

public class TestProject {
	public static void main(String args[]) {
		List carlist = new ArrayList();
		carlist.add(new Car("Toyota", "Altis", "SJC2456X", 100, 60));
		carlist.add(new Car("Toyota", "Vios", "SJG9523B", 100, 50));
		carlist.add(new Car("Nissan", "Latio", "SJB7412B", 100, 50));
		carlist.add(new Car("Murano", "SJC8761M", "Nissan", 300, 150));
		carlist.add(new Car("Honda", "Jazz", "SJB4875N", 100, 60));
		carlist.add(new Car("Honda", "Civic", "SJD73269C", 120, 70));
		carlist.add(new Car("Honda", "Stream", "SJL5169J", 120, 70));
		carlist.add(new Car("Honda", "Odyssey", "SJB3468E", 200, 150));
		carlist.add(new Car("Subaru", "WRX", "SJB8234L", 300, 200));
		carlist.add(new Car("Subaru", "Imprezza", "SJE8234K", 150, 80));
		Scanner input = new Scanner(;
		System.out.print("Enter model to rent: ");
		String model = input.nextLine();
		for (Car s : carlist) {
		if (model.equals(s.getModel())) {
		System.out.println("Model " + model + " is available");
		System.out.print("Enter number of days: ");
		int days = input.nextInt();
		int cost = (days * s.getRate()) + s.getDeposit();
		System.out.println("Deposit  DailyRate  Duration  TotalCost");
		System.out.println(s.getDeposit() + "       " + s.getRate()+ "            " + days + "        " + cost);
		System.out.print("Proceed to rent?( y/n ): ");
		String dec =;
		if (dec.equals("y")) {
		System.out.println("Enter Customer Name: ");
		String name =;
		System.out.println("Enter IC Number: ");
		int num = input.nextInt();
		System.out.println("Name   ICNo   Car  RegNo Duration   TCost");
		System.out.println(name + "   " + num + "   " + model
		+ "   " + s.getRegNo() + "   " + days + "   "+cost);
		System.out.println("Serving Next Customer ");
		} else if (dec.equals("n")) {
		System.out.println("Serving Next Customer: ");


Enter model to rent: Altis
Model Altis is available
Enter number of days: 2
Deposit   DailyRate   Duration   TotalCost
100          60                    2            220
Proceed to rent?( y/n ): y
Enter Customer Name:
Enter IC Number:
Name     ICNo     Car    RegNo    Duration    TCost
RoseIndia  1111   Altis  SJC2345X       2         220
Serving Next Customer


Posted on: February 4, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null