Advertisement
Guest User

Untitled

a guest
Aug 12th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.50 KB | None | 0 0
  1. import java.io.*;
  2. public class BusReservationAndTicketingSystem {
  3.  
  4.     public static void main(String args[]) throws IOException {
  5.     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  6.    
  7.     String user,password,yn,search,again,choice;
  8.     int to=0,y=1,z=0,end=0,r=1;
  9.     int available[] = new int[6];
  10.     int ticketI[][] = new int [100][3];
  11.     String ticketS[][] = new String[100][3];
  12.     double ticketD[][] = new double [100][3];
  13.     double pay[] = new double[20];
  14.     double change[] = new double[20];
  15.    
  16.     for(int i=1;i<4;){
  17.         System.out.print("Enter User: ");
  18.         user = in.readLine();
  19.         System.out.print("Enter Password: ");
  20.         password = in.readLine();
  21.    
  22.         //"available[]" is the SEAT AVAILABLE//
  23.         //store 20 seats every destination [1-5]//
  24.         for(int o=1; o<=5; o++){
  25.             available[o]=20;
  26.         }
  27.    
  28.         //if user and password are correct proceed to MAIN MENU//
  29.         if(user.equals("1") && password.equals("1")){
  30.        
  31.             for(int x=1; x==1;){
  32.                 //the MAIN MENU//
  33.                 System.out.println("********************************************");
  34.                 System.out.println("** BUS RESERVATION AND TICKETING SYSTEM   **");
  35.                 System.out.println("********************************************");
  36.                 System.out.println("** [1] Destination                   **");
  37.                 System.out.println("** [2] Passengers                    **");
  38.                 System.out.println("** [3] Billing                       **");
  39.                 System.out.println("** [4] View                          **");
  40.                 System.out.println("** [5] Exit                          **");
  41.                 System.out.println("***************************************");
  42.                 System.out.println("***************************************\n");
  43.        
  44.                 for(x=1; x==1;){
  45.                     System.out.print("ENTER CHOICE: ");
  46.                     choice=in.readLine();
  47.                    
  48.                     //if CHOICE is "1" display the DESTINATION//
  49.                     if (choice.equals("1")){
  50.                         //the DESTINATION DETAILS//
  51.                         //display the "Destination", every destination "Fare", and the "Seat" available//
  52.                         System.out.println("***************************************");
  53.                         System.out.println("**   DESTINATION   |  FARE  |  SEAT  **");
  54.                         System.out.println("***************************************");
  55.                         System.out.println("** 1.)DAVAO CITY   | Php600 |   "+available[1]+"   **");
  56.                         System.out.println("** 2.)BUTUAN CITY  | Php170 |   "+available[2]+"   **");
  57.                         System.out.println("** 3.)CABADBARAN   | Php150 |   "+available[3]+"   **");
  58.                         System.out.println("** 4.)TANDAG       | Php200 |   "+available[4]+"   **");
  59.                         System.out.println("** 5.)CAGAYAN      | Php250 |   "+available[5]+"   **");
  60.                         System.out.println("***************************************");
  61.                         System.out.println("***************************************\n");
  62.                         System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");   
  63.                         x=0;
  64.                     }
  65.                    
  66.                     //if CHOICE is "2" proceed to Ticket Booking//
  67.                     else if (choice.equals("2")){
  68.                         int print=1;
  69.                        
  70.                        
  71.                        
  72.                         //display first the Destination Details//
  73.                         System.out.println("***************************************");
  74.                         System.out.println("**   DESTINATION   |  FARE  |  SEAT  **");
  75.                         System.out.println("***************************************");
  76.                         System.out.println("** 1.)DAVAO CITY   | Php600 |   "+available[1]+"   **");
  77.                         System.out.println("** 2.)BUTUAN CITY  | Php170 |   "+available[2]+"   **");
  78.                         System.out.println("** 3.)CABADBARAN   | Php150 |   "+available[3]+"   **");
  79.                         System.out.println("** 4.)TANDAG       | Php200 |   "+available[4]+"   **");
  80.                         System.out.println("** 5.)CAGAYAN      | Php250 |   "+available[5]+"   **");
  81.                         System.out.println("***************************************");
  82.                         System.out.println("***************************************\n");
  83.                         System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
  84.                        
  85.                         if((available[1]==0)&&(available[2]==0)&&(available[3]==0)&&(available[4]==0)&&(available[5]==0)){
  86.                             System.out.println("Sorry, We don't  have available seats for all Destination!");
  87.                             x=0;
  88.                            
  89.                         }
  90.                        
  91.                        
  92.                        
  93.                         //inputing of Passenger's Name//
  94.                         else{
  95.                         for(x=1; x==1;){
  96.                             System.out.print("\nENTER PASSENGER'S NAME: ");
  97.                             ticketS[z][0] = in.readLine();
  98.                            
  99.                             x=0;
  100.                            
  101.                             //if Passenger's Name already used, display error and go back to Inputing//
  102.                             for(int l=0; l<z; l++){
  103.                                 if(ticketS[l][0].equalsIgnoreCase(ticketS[z][0])){
  104.                                     System.out.println("Sorry, Passenger's name have already used!");
  105.                                     x=1;
  106.                                 }
  107.                             }
  108.                         }
  109.                        
  110.                         //inputing of Destination//
  111.                         //integers Only [1-5]//
  112.                         for(x=1; x==1;){
  113.                             System.out.print("ENTER DESTINATION: ");
  114.                             to = Integer.parseInt(in.readLine());
  115.                            
  116.                             //if Inputed integers are "<1" or ">5", display error and go back to Inputing//
  117.                             if(to<1 || to>5){
  118.                                 System.out.println("Invalid Input!");
  119.                                 x=1;
  120.                             }
  121.                             //if available seat is eqaul to "Zero", display error and go back to Inputing//
  122.                             for(int d=1; d<=5; d++){
  123.                                 if(to==d){
  124.                                     if(available[to]==0){
  125.                                         System.out.println("Sorry, We don't have available seat!");
  126.                                         x=1;
  127.                                     }
  128.                                     x=0;
  129.                                 }
  130.                             }
  131.                         }
  132.                        
  133.                         //convert the integer to string//
  134.                         String dest[] = { " ", "DAVAO CITY", "BUTUAN CITY", "CABADBARAN", "TANDAG", "CAGAYAN"};
  135.                         double fare[] = { 0,600,170,150,200,250};
  136.            
  137.                         //converted integer to string, transfer to storage array//
  138.                         ticketS[z][1] = dest[to];
  139.                         ticketD[z][0] = fare[to];
  140.                        
  141.                         //inputing for Number of Passenger's//
  142.                         for(x=1; x==1;){
  143.                         System.out.print("HOW MANY PASSENGERS ARE YOU?: ");
  144.                         ticketI[z][0] = Integer.parseInt(in.readLine());
  145.            
  146.                             //subtract the available seat by the the number inputed//
  147.                             for(int p=1; p<=5; p++){
  148.                                 if(to==p){
  149.                                     print=1;
  150.                                     available[to] = available[to]-ticketI[z][0];
  151.                                    
  152.                                     //if the subtracted available seat is "<0", display error//
  153.                                     //add the inputed number to the subtracted seat, to back the original seat//
  154.                                     //display the available seat and back to the inputing//
  155.                                     if(available[to]<0){
  156.                                         System.out.print("Sorry, We don't have seat available for " +ticketI[z][0] +" person\n");
  157.                                         available[to] = available[to]+ticketI[z][0];
  158.                                         System.out.print("We only have " +available[to] +" seat available\n");
  159.                                         x=1;
  160.                                         print=0;
  161.                                     }
  162.                                     else{
  163.                                         x=0;
  164.                                     }
  165.                                 }
  166.                             }
  167.            
  168.                         }
  169.                        
  170.                         //inputing for Number of Discounted Passenger's//
  171.                         for(x=1;x==1;){
  172.                             System.out.print("HOW MANY PASSENGERS HAVE DISCOUNT?: ");
  173.                             ticketI[z][1] = Integer.parseInt(in.readLine());
  174.                        
  175.                             if(ticketI[z][1]>ticketI[z][0]){
  176.                                
  177.                                 System.out.println("Invalid Input!");
  178.                                 System.out.println("No. of Passengers are only " +ticketI[z][0] +"!");
  179.                             x=1;
  180.                             }
  181.                             else{
  182.                                 break;
  183.                             }
  184.                         }
  185.            
  186.            
  187.                         //print out of passengers details....
  188.                         if(print==1){
  189.                             System.out.println("\n***************************************");
  190.                             System.out.println("**        PASSENGER'S DETAILS        **");
  191.                             System.out.println("***************************************");
  192.                             System.out.println("PASSENGER'S NAME: " + ticketS[z][0]);
  193.                             System.out.println("PASSENGER'S DESTINATION : " + ticketS[z][1]);
  194.                             System.out.println("FARE PRICE: Php " + ticketD[z][0]);
  195.                             System.out.println("NO. OF PASSENGERS: " + ticketI[z][0]);
  196.                             System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[z][1]);
  197.                             System.out.println("***************************************");
  198.                             System.out.println("***************************************\n");
  199.                             ticketS[z][2]="0";
  200.                             double discount=(ticketD[z][0]-(ticketD[z][0]*0.2))*ticketI[z][1];
  201.                             ticketD[z][2]= ((ticketI[z][0]-ticketI[z][1])*ticketD[z][0])+discount;
  202.                             x=0;
  203.                         }
  204.                         z++;
  205.                         }
  206.                     }
  207.                    
  208.                     else if (choice.equals("3")){
  209.                      
  210.                        
  211.                         for(x=1; x==1;){
  212.                            
  213.                                 System.out.print("ENTER PASSENGER'S NAME: ");
  214.                                 search = in.readLine();
  215.                                
  216.                                
  217.                                 int s=1;
  218.                                 for(int b=0;b<z;b++){
  219.                                     if(search.equalsIgnoreCase(ticketS[b][0])){
  220.                                         System.out.println("***************************************");
  221.                                         System.out.println("**        PASSENGER'S DETAILS        **");
  222.                                         System.out.println("***************************************");
  223.                                         System.out.println("PASSENGER'S NAME: " + ticketS[b][0]);
  224.                                         System.out.println("PASSENGER'S DESTINATION : " + ticketS[b][1]);
  225.                                         System.out.println("FARE PRICE: Php" + ticketD[b][0]);
  226.                                         System.out.println("NO. OF PASSENGERS: " + ticketI[b][0]);
  227.                                         System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[b][1]);
  228.                                         System.out.println("***************************************");
  229.                                         System.out.println("***************************************");
  230.                                         s=0;
  231.                                         x=0;
  232.                                        
  233.                                         if(ticketS[b][2].equals("x")){
  234.                                             System.out.println("Passenger's Already Paid!");
  235.                                             x=0;
  236.                                         }
  237.                                         else{
  238.                                             ticketS[b][2]="x";
  239.                                            
  240.                                        
  241.                                             for(x=1; x==1;){
  242.                                                 System.out.println("\nPASSENGER'S TOTAL FARE: Php "+ticketD[b][2]);
  243.                                                 System.out.print("ENTER AMOUNT TO PAY: ");
  244.                                                 pay[b] = Double.parseDouble(in.readLine());
  245.                                                 change[b]=pay[b]-ticketD[b][2];
  246.                                    
  247.                                                 if(change[b]<0){
  248.                                                     System.out.println("Invalid Input!");
  249.                                                     x=1;
  250.                                                 }
  251.                                                 else{
  252.                                                     System.out.println("CHANGE: Php "+change[b]);
  253.                                                     System.out.println("");
  254.                                                     x=0;
  255.                                                 }
  256.                                             }
  257.                                         }
  258.                                     }
  259.                                 }
  260.                                 if (s==1){
  261.                                     System.out.println("\nPASSENGER'S NAME NOT FOUND!\n");
  262.                                     for(int q=1; q==1;){
  263.                                    
  264.                                     System.out.print("Do you wish to continue with this transaction? [Y/N]: ");
  265.                                     again=in.readLine();
  266.                                    
  267.                                     if(again.equalsIgnoreCase("y")){
  268.                                         q=0;
  269.                                     }
  270.                                     else if (again.equalsIgnoreCase("n")){
  271.                                         q=0;
  272.                                         x=0;
  273.                                        
  274.                                     }
  275.                                     else{
  276.                                         System.out.println("\nInvalid input!\n");
  277.                                     }
  278.                                
  279.                        
  280.                                 }
  281.                             }  
  282.                         }
  283.                        
  284.                     }
  285.                    
  286.                     else if (choice.equals("4")){
  287.                        
  288.                        
  289.                         for(int sx=1; sx<=3;){
  290.                         System.out.print("SEARCH PASSENGER'S NAME: ");
  291.                         search = in.readLine();
  292.                
  293.                         int s=1;
  294.                             for(x=0; x<=z; x++){
  295.                                 if(search.equalsIgnoreCase(ticketS[x][0])){
  296.                                     System.out.println("***************************************");
  297.                                     System.out.println("**        PASSENGER'S DETAILS        **");
  298.                                     System.out.println("***************************************");
  299.                                     System.out.println("PASSENGER'S NAME: " + ticketS[x][0]);
  300.                                     System.out.println("PASSENGER'S DESTINATION : " + ticketS[x][1]);
  301.                                     System.out.println("FARE PRICE: Php" + ticketD[x][0]);
  302.                                     System.out.println("NO. OF PASSENGERS: " + ticketI[x][0]);
  303.                                     System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[x][1]);
  304.                                     System.out.println("TOTAL FARE PRICE: Php " + ticketD[x][2]);
  305.                                     if(ticketS[x][2].equals("x")){
  306.                                         System.out.println("PAY: Php " +pay[x]);
  307.                                         System.out.println("CHANGE: Php " +change[x]);
  308.                                         System.out.println("STATUS: PAID");
  309.                                     }
  310.                                     else{
  311.                                         System.out.println("STATUS: NOT PAID");
  312.                                     }
  313.                                     System.out.println("***************************************");
  314.                                     System.out.println("***************************************");
  315.                                     s=0;
  316.                                     sx=4;
  317.                                 }
  318.                             }  
  319.                        
  320.                            
  321.                             if (s==1){
  322.                                 System.out.println("Passenger's Name not found!");
  323.                                 sx++;
  324.                             }
  325.                            
  326.                         }
  327.                     }      
  328.                    
  329.                     else if(choice.equals("5")){
  330.                         end=1;
  331.                         x=0;
  332.                         System.out.println("Thank You!");
  333.                     }
  334.                
  335.                     else{
  336.                         System.out.println("Invalid Input!");
  337.                         x=1;
  338.                     }
  339.                 }
  340.        
  341.                 for(y=1; y==1;){
  342.                     if(end==1){
  343.                         break;
  344.                     }
  345.                     System.out.print("Do you want another transaction? [Y/N]: ");
  346.                     yn = in.readLine();
  347.        
  348.                     if (yn.equalsIgnoreCase("y")){
  349.                         x=1;
  350.                         y=0;
  351.                     }
  352.                     else if (yn.equalsIgnoreCase("n")){
  353.                         System.out.println("\nThank You!!!");
  354.                         break;
  355.                     }
  356.                     else{
  357.                         System.out.println("Invalid Input!!!");
  358.                         y=1;
  359.                     }
  360.                 }
  361.             }
  362.             i=4;
  363.         }
  364.         else{
  365.             System.out.println("\nInvalid user or password!\n");
  366.             i++;
  367.         }
  368.    
  369.     }
  370.    
  371.     }
  372.    
  373.    
  374. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement