0% found this document useful (0 votes)
68 views6 pages

Taxi Booking System

The document outlines a Java-based taxi booking system that allows users to book taxis and view taxi details. It includes classes for Taxi, Booking, and the main application logic, which manages user input and taxi availability. The system checks for available taxis based on pickup time and calculates the fare based on the distance between pickup and destination points.

Uploaded by

MADHUMITHA A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views6 pages

Taxi Booking System

The document outlines a Java-based taxi booking system that allows users to book taxis and view taxi details. It includes classes for Taxi, Booking, and the main application logic, which manages user input and taxi availability. The system checks for available taxis based on pickup time and calculates the fare based on the distance between pickup and destination points.

Uploaded by

MADHUMITHA A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Taxi booking system

import java.util.*;

class Main {

public static void main(String[] args) {

List<Taxi> taxiList=new ArrayList<>();

for(int i=1;i<=4;i++){

Taxi t=new Taxi();

taxiList.add(t);

Booking book=new Booking();

while(true){
System.out.println("Welcome to Taxi Booking System");

System.out.println("Enter your choice:");

System.out.println("1 -> Book Taxi");

System.out.println("2 -> View Taxi Details");

Scanner sc=new Scanner(System.in);

int choice=sc.nextInt();

switch(choice){

case 1:{

System.out.println("Enter Customer Id:");

int custId=sc.nextInt();

System.out.println("Enter PickupPoint:");

char pickupPoint=sc.next().charAt(0);

if(!(pickupPoint>='A'&&pickupPoint<='F')){

System.out.println("Choose correct available Area between A,B,C,D,E,F");

return;

System.out.println("Enter DestinationPoint:");

char dropPoint=sc.next().charAt(0);

if(!(dropPoint>='A'&&dropPoint<='F')){

System.out.println("Choose correct available Area between A,B,C,D,E,F");

return;

System.out.println("Enter Pickup Time: From 6");

int pickupTime=sc.nextInt();

List<Taxi> freeTaxi=new ArrayList<>();

for(Taxi t:taxiList){

if((t.freeTime+Math.abs(t.currentPoint-pickupPoint)<=pickupTime))

{
freeTaxi.add(t);

if(freeTaxi.size()==0){

System.out.println("Taxi not available on your pickuptime");

break;

Taxi allotedTaxi=freeTaxi.get(0);

for(int i=1;i<freeTaxi.size();i++){

if(freeTaxi.get(i).totalEarning<allotedTaxi.totalEarning){

allotedTaxi=freeTaxi.get(i);

book.bookTaxi(custId,pickupPoint,dropPoint,pickupTime,allotedTaxi);

break;

case 2:{

for(Taxi t:taxiList){

System.out.print("Taxi"+t.id);

System.out.println(" TotalEarnings:"+t.totalEarning);

t.viewBookings();

break;

default:

System.out.println("Exit");
break;

// book.BookTaxi(1,'A','D',9,a);

// book.BookTaxi(2,'B','D',9,a);

// book.BookTaxi(8,'B','E',9,a);

// a.viewBookings();

class Taxi{

static int count=0;

int id;

int freeTime;

char currentPoint;

int totalEarning;

List<String> bookings;

Taxi(){

Taxi.count=Taxi.count+1;

id=this.count;

freeTime=6;

currentPoint='A';

totalEarning=0;

bookings=new ArrayList<>();

public void addBooking(int id,int custId,char source,char dest,int pickupTime,int dropTime,int


amount){

String booking=id+" "+custId+" "+source+" "+dest+" "+pickupTime+" "+dropTime+"


"+amount;

this.bookings.add(booking);
this.freeTime=dropTime;

this.currentPoint=dest;

this.totalEarning+=amount;

public void viewBookings(){

System.out.println("BookingId"+" "+"CustomerId"+" "+"Source"+" "+"Destination"+"


"+"PickupTime"+" "+"DropTime"+" "+"Amount");

for(String s:bookings){

System.out.println(s);

class Booking{

static int count=0;

int id;

int custId;

char source;

char dest;

int pickupTime;

int dropTime;

int amount;

Booking(){

Booking.count=0;

this.id=count;

}
public void bookTaxi(int customerId,char Source,char Destination,int pickupTime,Taxi a){

Booking.count+=1;

this.id=count;

this.custId=customerId;

this.source=Source;

this.dest=Destination;

this.pickupTime=pickupTime;

this.dropTime=pickupTime+Math.abs(Source-Destination);

this.amount=((Math.abs(Source-Destination)*15)-5)*10+100;

a.addBooking(this.id,this.custId,this.source,this.dest,this.pickupTime,this.dropTime,this.amount);

System.out.println("Taxi "+a.id+"Booked Successfully");

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy