0% found this document useful (0 votes)
37 views

PF Project Java

The document describes a bus reservation system for Shahjee Travels. It defines methods for displaying the reservation menu and processing reservations. The menu method lists the available routes and buses. The route method allows the user to select a route, number of seats, and displays reservation details like available seats, fare, and total cost. It validates the input and handles errors like unavailable seats before completing the reservation.

Uploaded by

aleesakhan28
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

PF Project Java

The document describes a bus reservation system for Shahjee Travels. It defines methods for displaying the reservation menu and processing reservations. The menu method lists the available routes and buses. The route method allows the user to select a route, number of seats, and displays reservation details like available seats, fare, and total cost. It validates the input and handles errors like unavailable seats before completing the reservation.

Uploaded by

aleesakhan28
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package javaapplication70;

import java.util.Scanner;

public class JavaApplication70 {


public static void menu(){
System.out.println("welcome to shahjee travels");
System.out.println("available buses are 5");
System.out.println("press 1 if you want to travel from attock to islamabad");
System.out.println("press 2 if you want to travel from attock to peshawar");
System.out.println("press 3 if you want to travel from attock to lahore");
System.out.println("press 4 if you want to travel from attock to karachi");
System.out.println("press 5 if you want to travel from attock to hazro");
System.out.println("refund not available");
}
public static void route(){
int[] seats= {15,16,18,10,12};
int[] fare={1000,800,1500,2000,200};
Scanner sc= new Scanner (System.in);
System.out.println("choose your route:");
int route=sc.nextInt();
if(route >0 && route <=5){
System.out.println("how many seats you want to reserve");
int seats_r=sc.nextInt();
switch (route){
case 1:
if(seats_r>seats[0]){
System.out.println("more than available seats");
}
else if(seats_r==0){
System.out.println("you did not reserved any seats");
}
else{
System.out.println("total available seats in bus 1 are: " +seats[0]+ "\
nfare per seat is: "+fare[0]);
System.out.println("reserved seats are: "+seats_r+"\nremaining seats
are: "+(seats[0]-seats_r)+"\ntotal fare is: "+(seats_r*fare[0]));}
break;
case 2:
if(seats_r>seats[1]){
System.out.println("more than available seats");
}
else if(seats_r==0){
System.out.println("you did not reserved any seats");
}
else{
System.out.println("total available seats in bus 2 are: "+seats[1]+"\
nfare per seat is: "+fare[1]);
System.out.println("reserved seats are: "+seats_r+"\nremaining seats
are: "+(seats[1]-seats_r)+"\ntotal fare is: "+(seats_r*fare[1]));}
break;
case 3:
if(seats_r>seats[2]){
System.out.println("more than available seats");
}
else if(seats_r==0){
System.out.println("you did not reserved any seats");
}
else{
System.out.println("total available seats in bus 3 are: "+seats[2]+"\
nfare per seat is: "+fare[2]);
System.out.println("reserved seats are: "+ seats_r+"\nremaining seats
are: "+(seats[2]-seats_r)+"\n total fare is: "+(seats_r*fare[2]));
} break;
case 4:
if(seats_r>seats[3]){
System.out.println("more than available seats");
}
else if(seats_r==0){
System.out.println("you did not reserved any seats");
}
else{
System.out.println("total available seats in bus 4 are: "+ seats[3]+"\
nfare per seat is: "+fare[3]);
System.out.println("reserved seats are: "+ seats_r+"\nremaining seats
are: "+(seats[3]-seats_r)+"\ntotal fare is:"+(seats_r*fare[3]));
}break;
case 5:
if(seats_r>seats[4]){
System.out.println("more than available seats");
}
else if(seats_r==0){
System.out.println("you did not reserved any seats");
}
else{
System.out.println("total available seats in bus 5 are: "+seats[4]+"\
nfare per seat is "+fare[4]);
System.out.println("reserved seats are: "+ seats_r+"\nremaining seats
are: "+(seats[4]-seats_r)+"\ntotal fare is: "+(seats_r*fare[4]));
} break;
}}
else{
System.out.println("invalid input");
}

public static void main(String[] args) {


menu();
route();
}
}

You might also like