Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.InputMismatchException;
- public class busReservationFinal {
- public static void main(String args[]) throws IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- Scanner sc = new Scanner(System.in);
- String user,password,yn,search = null,again,choice;
- int to=0,y=1,z=0,end=0,r=1, bn = 1, ab=0, g=0, mn;
- boolean w = true;
- int available[] = new int[100];
- int busN[] = new int[200];
- int ticketI[][] = new int [100][3];
- String Driver[] = new String[0];
- String Cond[] = new String[0];
- String Empl[] = new String[0];
- String Posi[] = new String[0];
- String ticketS[][] = new String[100][3];
- double ticketD[][] = new double [100][3];
- double pay[] = new double[20];
- double change[] = new double[20];
- for(int o=1; o<=5; o++){
- available[o]=60;
- }
- for(int mm = 1; mm==1;){
- /*while(g==0) {
- try { */
- System.out.println("-MAIN MENU-");
- System.out.println("[0]Admin");
- System.out.println("[1]Staff");
- System.out.println("[2]Exit");
- System.out.print("Enter your choice: ");
- mn = sc.nextInt();
- /* break;
- }
- catch (InputMismatchException e) {
- System.out.println("-INVALID INPUT!-");
- System.out.println();
- sc.next();
- g=0;
- }
- } */
- switch(mn){
- case 0:
- for(int i=2;i==2;){
- System.out.println();
- System.out.println("Admin Login");
- System.out.print("Enter User: ");
- user = in.readLine();
- System.out.print("Enter Password: ");
- password = in.readLine();
- if(user.equalsIgnoreCase("Admin") && password.equalsIgnoreCase("1234")){
- for(int x=1; x==1;){
- System.out.println("--------------------------------------------");
- System.out.println("| BUS RESERVATION AND TICKETING SYSTEM |");
- System.out.println("|------------------------------------------|");
- System.out.println("|[1] Bus - Driver/Conductor Details |");
- System.out.println("|[2] Employees |");
- System.out.println("|[3] Customers |");
- System.out.println("|[4] Destination and Fare |");
- System.out.println("|[5] Sales |");
- System.out.println("|[6] Exit |");
- System.out.println("|------------------------------------------|");
- System.out.println("--------------------------------------------\n");
- busN[ab] = bn;
- for(x=1; x==1;){
- for(int rr=0; rr==0;) {
- System.out.print("Enter Choice: ");
- int choice1 = Integer.parseInt(in.readLine());
- System.out.println();
- if(choice1<=6) {
- switch(choice1){
- //CASE 1 BUS DRIVER CONDUCTOR DETAILS
- case 1:
- for(int hh=0;hh==0;) {
- System.out.println("[0]view [1]add [2]edit [3]search [4]delete [5]back\n");
- int choice2 = Integer.parseInt(in.readLine());
- if(choice2<=5) {
- //case 1 case 0 view
- switch(choice2){
- case 0:
- System.out.println("[View]");
- System.out.println("**********************************************************");
- System.out.println("**\tBUS NO.\t|\tDRIVER\t|\tCONDUCTOR\t");
- System.out.println("**********************************************************");
- for(int a = 0; a < Driver.length; a++){
- if(Driver[a] == null)
- Driver[a]="";
- if(Cond[a]==null)
- Cond[a]="";
- System.out.println("**\t"+ busN[a]+"\t|\t" + Driver[a] +"\t| "+Cond[a]);
- }
- System.out.println("**********************************************************");
- System.out.println("**********************************************************\n");
- rr=1;
- break;
- //case 1 case 1 add
- case 1:
- System.out.println("[Add]");
- System.out.println("Number of bus to add: ");
- ArrayList<String> myList = new ArrayList<String>(Arrays.asList(Driver));
- ArrayList<String> myListt = new ArrayList<String>(Arrays.asList(Cond));
- int size = Integer.parseInt(in.readLine());
- System.out.println("Enter Bus Driver and Conductor Name:");
- for(int gg = 0; gg < size; gg++){
- System.out.println();
- System.out.println("Driver: ");
- String element1 = in.readLine().toUpperCase();
- System.out.println("Conductor: ");
- String element2 = in.readLine().toUpperCase();
- myList.add(element1);
- myListt.add(element2);
- }
- Driver = myList.toArray(Driver);
- Cond = myListt.toArray(Cond);
- System.out.println("Successfully Added");
- rr=1;
- break;
- //case 1 case 2 edit
- case 2:
- System.out.println("[Edit]");
- do {
- System.out.println("Enter Bus Number:");
- choice1 = Integer.parseInt(in.readLine());
- int s = 1;
- for(int ss = 0; ss < Driver.length; ss++) {
- if(choice1==busN[ss]) {
- while(w==true) {
- System.out.println("[0] Driver");
- System.out.println("[1] Conductor");
- choice2 = Integer.parseInt(in.readLine());
- if(choice2==0) {
- System.out.println("Enter to edit: ");
- search = in.readLine();
- Driver[ss] = search.toUpperCase();
- System.out.println("Edit succesful.");
- w=false;
- }
- else if(choice2==1){
- System.out.println("Enter to edit: ");
- search = in.readLine();
- Cond[ss] = search.toUpperCase();
- System.out.println("Edit succesful.");
- w=false;
- }
- else {
- System.out.println("Invalid Input.");
- w = true;
- }
- s=0;
- }
- }
- }
- if (s==1){
- System.out.println("Bus Number Not Found!");
- g=1;
- }
- else{
- g=0;
- }
- x=0;
- }while(g==1);
- rr=1;
- break;
- //case 1 case 3 search
- case 3:
- System.out.println("[Search]");
- System.out.println("Enter a name to search: ");
- search = in.readLine();
- for(int ss = 0; ss < Driver.length; ss++){
- if(search.equalsIgnoreCase(Driver[ss]) || search.equalsIgnoreCase(Cond[ss])){
- System.out.println("******************************************");
- System.out.println("** BUS NO. | DRIVER | CONDUCTOR **");
- System.out.println("***************************************");
- System.out.println("** " + busN[ss] + " | " + Driver[ss] + " | " +Cond[ss]+" **");
- System.out.println("******************************************");
- System.out.println("******************************************\n");
- }
- }
- rr=1;
- break;
- case 4:
- System.out.println("[Delete]");
- ArrayList<String> myList1 = new ArrayList<String>(Arrays.asList(Driver));
- ArrayList<String> myListt2 = new ArrayList<String>(Arrays.asList(Cond));
- System.out.println("[0]Driver");
- System.out.println("[1]Conductor");
- choice1 = Integer.parseInt(in.readLine());
- if(choice1==0) {
- System.out.println("Enter name: ");
- String element1 = in.readLine();
- String element11 = element1.toUpperCase();
- myList1.remove(element11);
- Driver = myList1.toArray(Driver);
- System.out.println("Successfully Deleted");
- }
- else {
- System.out.println("Enter name: ");
- String element2 = in.readLine();
- String element22=element2.toUpperCase();
- myListt2.remove(element22);
- Cond = myListt2.toArray(Cond);
- System.out.println("Successfully Deleted");
- }
- rr=1;
- break;
- case 5:
- rr=1;
- break;
- }
- hh=1;
- }
- else {
- System.out.println("INVALID INPUT");
- hh = 0;
- }
- }
- break;
- //CASE 2 EMPLOYEES
- case 2:
- System.out.println("[Employees]");
- for(int nn = 0; nn==0;) {
- System.out.println("[0]view [1]add [2]edit [3]search [4]delete [5]back\n");
- int choice3 = Integer.parseInt(in.readLine());
- if(choice3<=5) {
- switch(choice3){
- //case 2 employees case 0 view
- case 0:
- System.out.println("[View]");
- System.out.println("**********************************************************");
- System.out.println("** Employee's Name | Position **");
- System.out.println("**********************************************************");
- for(int a = 0; a < Empl.length; a++){
- if(Empl[a] == null)
- Empl[a]="";
- if(Posi[a]==null)
- Posi[a]="";
- System.out.println("**\t" + Empl[a] +"\t|\t"+ Posi[a]+"\t**");
- }
- System.out.println("******************************************");
- System.out.println("******************************************\n");
- rr=1;
- break;
- //case 2 employees case 1 add
- case 1:
- System.out.println("[Add]");
- System.out.println("Number of Employee's to add: ");
- ArrayList<String> myList1 = new ArrayList<String>(Arrays.asList(Empl));
- ArrayList<String> myList2 = new ArrayList<String>(Arrays.asList(Posi));
- int size = Integer.parseInt(in.readLine());
- System.out.println("Enter Employee's Name and Position:");
- for(int gg = 0; gg < size; gg++){
- System.out.println();
- System.out.println("Employee: ");
- String element1 = in.readLine();
- System.out.println("Position: ");
- String element2 = in.readLine();
- myList1.add(element1);
- myList2.add(element2);
- }
- Empl = myList1.toArray(Empl);
- Posi = myList2.toArray(Posi);
- System.out.println("Successfully Added");
- rr=1;
- mm=3;
- break;
- //case 2 employees case 2 edit
- case 2:
- while(w==true) {
- System.out.println("[Edit]");
- System.out.println("[0] Employee");
- System.out.println("[1] Position");
- choice1 = Integer.parseInt(in.readLine());
- if(choice1==0){
- while(w==true) {
- System.out.println("Search a name to edit: ");
- search = in.readLine();
- for(int ss = 0; ss < Empl.length; ss++){
- if(search.equalsIgnoreCase(Empl[ss])){
- System.out.println("******************************************");
- System.out.println("** Employee | Position **");
- System.out.println("***************************************");
- System.out.println("** " + Empl[ss] + " | " +Posi[ss]+" **");
- System.out.println("******************************************");
- System.out.println("******************************************\n");
- System.out.println("Edit to: ");
- search = in.readLine();
- Empl[ss] = search;
- System.out.println("Edit Successful!");
- System.out.println("******************************************");
- System.out.println("** Employee | Position **");
- System.out.println("***************************************");
- System.out.println("** " + Empl[ss] + " | " +Posi[ss]+" **");
- System.out.println("******************************************");
- System.out.println("******************************************\n");
- w = false;
- break;
- }
- else {
- System.out.println("INVALID INPUT");
- w= true;
- }
- }
- }
- }
- if (choice1==1){
- while(w==true) {
- System.out.println("Search a name to edit: ");
- String search1=in.readLine();
- for(int aa=0; aa<Posi.length; aa++){
- if(search1.equalsIgnoreCase(Posi[aa])){
- System.out.println("******************************************");
- System.out.println("** Employee | Position **");
- System.out.println("***************************************");
- System.out.println("** " + Empl[aa] + " | " +Posi[aa]+" **");
- System.out.println("******************************************");
- System.out.println("******************************************\n");
- System.out.println("Edit to: ");
- search1 = in.readLine();
- Posi[aa] = search1;
- System.out.println("Edit Successful!");
- System.out.println("******************************************");
- System.out.println("** Employee | Position **");
- System.out.println("***************************************");
- System.out.println("** " + Empl[aa] + " | " +Posi[aa]+" **");
- System.out.println("******************************************");
- System.out.println("******************************************\n");
- w= false;
- break;
- }
- else {
- System.out.println("No result for " + search);
- w= true;
- }
- }
- }
- }
- if(choice1<0 || choice1>6) {
- System.out.println("INVALID INPUT");
- w=true;
- }
- }
- rr=1;
- break;
- //case 2 employees case 3 search
- case 3:
- System.out.println("[Search]");
- for(int aaa=0; aaa==0;) {
- System.out.println("Enter a name to search: ");
- search = in.readLine();
- for(int ss = 0; ss < Empl.length; ss++){
- if(search.equalsIgnoreCase(Empl[ss]) || search.equalsIgnoreCase(Posi[ss])){
- System.out.println("******************************************");
- System.out.println("** Employee | Position **");
- System.out.println("***************************************");
- System.out.println("** " + Empl[ss] + " | " +Posi[ss]+" **");
- System.out.println("******************************************");
- System.out.println("******************************************\n");
- aaa=1;
- }
- else {
- System.out.println("Name not found.");
- aaa=0;
- }
- }
- }
- rr=1;
- break;
- //case 2 employees case 4 delete
- case 4:
- System.out.println("[Delete]");
- System.out.println("Number of employees to remove: ");
- ArrayList<String> myList3 = new ArrayList<String>(Arrays.asList(Empl));
- ArrayList<String> myList4 = new ArrayList<String>(Arrays.asList(Posi));
- int size1 = Integer.parseInt(in.readLine());
- for(int yy=0; yy==0;) {
- System.out.println("Enter employee name: ");
- for(int gg = 0; gg < size1; gg++){
- System.out.println();
- System.out.println("Employee: ");
- String element1 = in.readLine();
- if(element1.equalsIgnoreCase(Empl[gg])) {
- //System.out.println("Position: ");
- //String element2 = in.readLine();
- myList3.remove(element1);
- myList4.remove(Posi[gg]);
- yy=1;
- }
- else {
- System.out.println("Name not found.");
- yy=0;
- }
- }
- }
- Empl = myList3.toArray(Empl);
- Posi = myList4.toArray(Posi);
- System.out.println("Successfully Deleted");
- rr=1;
- break;
- //case 2 employees case 5 back
- case 5:
- x = 1;
- rr=1;
- break;
- }
- break;
- }
- else {
- System.out.println("INVALID INPUT");
- nn = 0;
- }
- }
- break;
- //CUSTOMERS
- case 3:
- System.out.println("[Customers]");
- System.out.println("[0]view [1]search\n");
- int choice4 = Integer.parseInt(in.readLine());
- switch(choice4){
- case 0:
- System.out.println("[View]");
- System.out.println("**********************************************************");
- System.out.println("** Customer's Name | Destination **");
- System.out.println("**********************************************************");
- for(int a = 0; a <z ; a++){
- System.out.println("**\t"+ ticketS[a][0] +"\t\t**\t"+ticketS[a][1]);
- }
- //z++;
- System.out.println("**********************************************************");
- System.out.println("**********************************************************\n");
- rr=1;
- mm=3;
- break;
- case 1:
- // System.out.println("Search Customer's Name: ");
- // search = in.readLine();
- // Search
- for(int sx=1; sx<=3;){
- System.out.print("SEARCH PASSENGER'S NAME: ");
- search = in.readLine();
- int s=1;
- for(x=0; x<=z; x++){
- if(search.equalsIgnoreCase(ticketS[x][0])){
- System.out.println("***************************************");
- System.out.println("** PASSENGER'S DETAILS **");
- System.out.println("***************************************");
- System.out.println("PASSENGER'S NAME: " + ticketS[x][0]);
- System.out.println("PASSENGER'S DESTINATION : " + ticketS[x][1]);
- System.out.println("FARE PRICE: Php" + ticketD[x][0]);
- System.out.println("NO. OF PASSENGERS: " + ticketI[x][0]);
- System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[x][1]);
- System.out.println("TOTAL FARE PRICE: Php " + ticketD[x][2]);
- if(ticketS[x][2].equals("x")){
- System.out.println("PAY: Php " +pay[x]);
- System.out.println("CHANGE: Php " +change[x]);
- System.out.println("STATUS: PAID");
- }
- else{
- System.out.println("STATUS: NOT PAID");
- }
- System.out.println("***************************************");
- System.out.println("***************************************");
- s=0;
- sx=4;
- }
- }
- if (s==1){
- System.out.println("Passenger's Name not found!");
- sx=1;
- }
- }
- rr=1;
- mm=3;
- }
- mm=3;
- rr=1;
- break;
- case 4:
- System.out.println("[Destination and Fare]");
- System.out.println("***************************************");
- System.out.println("** DESTINATION | FARE | SEAT **");
- System.out.println("***************************************");
- System.out.println("** 1.)DAVAO CITY | Php500 | "+available[1]+" **");
- System.out.println("** 2.)PANABO CITY | Php400 | "+available[2]+" **");
- System.out.println("** 3.)TAGUM CITY | Php300 | "+available[3]+" **");
- System.out.println("** 4.)NABUNTURAN | Php200 | "+available[4]+" **");
- System.out.println("** 5.)COMPOSTELA | Php100 | "+available[5]+" **");
- System.out.println("***************************************");
- System.out.println("***************************************\n");
- System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
- rr=1;
- break;
- case 5:
- for(int ss = 0; ss==0;) {
- System.out.println("[Sales]");
- System.out.println("[0]Daily");
- System.out.println("[1]Weekly");
- System.out.println("[2]Monthly");
- System.out.println("Enter choice: ");
- choice1 = sc.nextInt();
- if(choice1==0) {
- int sum = 0;
- for(int b = 0; b < z; b++) {
- sum+=ticketD[b][2];
- }
- System.out.println("[Daily]");
- System.out.println("DAYS"+"\t"+"|"+"\t"+"DAILY SALES");
- System.out.println("-----------------------------------------------------");
- String days[] = {"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
- System.out.println(days [1]+"\t\t"+"|\t"+sum);
- System.out.println(days [2]+"\t\t"+"|\t");
- System.out.println(days [3]+"\t"+"|\t");
- System.out.println(days [4]+"\t"+"|\t");
- System.out.println(days [5]+"\t\t"+"|\t");
- System.out.println(days [6]+"\t"+"|\t");
- System.out.println(days [7]+"\t\t"+"|\t");
- System.out.println("-----------------------------------------------------");
- System.out.println("TOTAL"+"\t\t"+ sum);
- System.out.println("-----------------------------------------------------");
- System.out.println();
- ss=1;
- }
- else if(choice1==1) {
- int sum = 0;
- for(int b = 0; b < z; b++) {
- sum+=ticketD[b][2];
- }
- System.out.println ("- WEEKLY SALES REPORT -");
- System.out.println("-----------------------------------------------------");
- System.out.println("WEEK"+"\t"+"|"+"\t\t"+"WEEKLY SALES");
- System.out.println("-----------------------------------------------------");
- String week[] = {"","Week 1","Week 2","Week 3","Week 4"};
- System.out.println(week [1]+"\t"+"|\t");
- System.out.println(week [2]+"\t"+"|\t"+sum);
- System.out.println(week [3]+"\t"+"|\t");
- System.out.println(week [4]+"\t"+"|\t");
- System.out.println("-----------------------------------------------------");
- System.out.println("TOTAL"+"\t\t"+sum);
- System.out.println("-----------------------------------------------------");
- System.out.println();
- ss=1;
- }
- else if(choice1==2) {
- int sum = 0;
- for(int b = 0; b < z; b++) {
- sum+=ticketD[b][2];
- }
- System.out.println ("- MONTHLY SALES REPORT -");
- System.out.println("-----------------------------------------------------");
- System.out.println("MONTH"+"\t\t"+"|"+"\t\t"+"MONTHLY SALES");
- System.out.println("-----------------------------------------------------");
- String month[] = {"","January","February","March","April","May","June","July","August","September","October","November","December"};
- System.out.println(month [1]+"\t\t"+"|\t");
- System.out.println(month [2]+"\t"+"|");
- System.out.println(month [3]+"\t\t"+"|");
- System.out.println(month [4]+"\t\t"+"|");
- System.out.println(month [5]+"\t\t"+"|");
- System.out.println(month [6]+"\t\t"+"|");
- System.out.println(month [7]+"\t\t"+"|");
- System.out.println(month [8]+"\t\t"+"|");
- System.out.println(month [9]+"\t"+"|");
- System.out.println(month [10]+"\t\t"+"|");
- System.out.println(month [11]+"\t"+"|");
- System.out.println(month [12]+"\t"+"|\t"+sum);
- System.out.println("-----------------------------------------------------");
- System.out.println("TOTAL"+"\t\t"+"|\t\t"+sum);
- System.out.println("-----------------------------------------------------");
- System.out.println();
- ss=1;
- }
- else{
- System.out.println("INVALID INPUT");
- ss=0;
- }
- }mm=0;
- rr=1;
- break;
- case 6:
- System.out.println("Exit...");
- rr=1;
- break;
- }
- }
- else {
- System.out.println("INVALID INPUT");
- rr=0;
- }
- }
- x=4;
- }
- bn++;
- ab++;
- r++;
- for(y=1; y==1;){
- if(end==1){
- break;
- }
- System.out.print("Do you want another transaction? [Y/N]: ");
- yn = in.readLine();
- if (yn.equalsIgnoreCase("y")){
- x=1;
- y=0;
- }
- else if (yn.equalsIgnoreCase("n")){
- System.out.println("\nThank You!!!");
- System.out.println();
- System.out.println();
- i=3;
- mm=1;
- break;
- }
- else{
- System.out.println("Invalid Input!!!");
- y=1;
- }
- }
- }
- i=4;
- }
- else{
- System.out.println("\nInvalid user or password!\n");
- i=2;
- }
- }
- break;
- /////////////////////////////////////////////////////////
- //STAFF
- case 1:
- // for(int i=1;i<10000;){
- for(int i=2;i==2;){
- System.out.println();
- System.out.println("Staff Login");
- System.out.print("Enter User: ");
- user = in.readLine();
- System.out.print("Enter Password: ");
- password = in.readLine();
- //"available[]" is the SEAT AVAILABLE//
- //store 60 seats every destination [1-5]//
- //if user and password are correct proceed to MAIN MENU//
- if(user.equalsIgnoreCase("Staff") && password.equalsIgnoreCase("1234")){
- for(int x=1; x==1;){
- //the MAIN MENU//
- System.out.println("--------------------------------------------");
- System.out.println("| BUS RESERVATION AND TICKETING SYSTEM |");
- System.out.println("|------------------------------------------|");
- System.out.println("|[1] Destination |");
- System.out.println("|[2] Passengers |");
- System.out.println("|[3] Billing |");
- System.out.println("|[4] View |");
- System.out.println("|[5] Exit |");
- System.out.println("|------------------------------------------|");
- System.out.println("--------------------------------------------\n");
- for(x=1; x==1;){
- System.out.print("Enter Choice: ");
- choice=in.readLine();
- System.out.println();
- //if CHOICE is "1" display the DESTINATION//
- if (choice.equals("1")){
- //the DESTINATION DETAILS//
- //display the "Destination", every destination "Fare", and the "Seat" available//
- System.out.println("***************************************");
- System.out.println("** DESTINATION | FARE | SEAT **");
- System.out.println("***************************************");
- System.out.println("** 1.)DAVAO CITY | Php500 | "+available[1]+" **");
- System.out.println("** 2.)PANABO CITY | Php400 | "+available[2]+" **");
- System.out.println("** 3.)TAGUM CITY | Php300 | "+available[3]+" **");
- System.out.println("** 4.)NABUNTURAN | Php200 | "+available[4]+" **");
- System.out.println("** 5.)COMPOSTELA | Php100 | "+available[5]+" **");
- System.out.println("***************************************");
- System.out.println("***************************************\n");
- System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
- x=0;
- }
- //if CHOICE is "2" proceed to Ticket Booking//
- else if (choice.equals("2")){
- int print=1;
- //display first the Destination Details//
- System.out.println("***************************************");
- System.out.println("** DESTINATION | FARE | SEAT **");
- System.out.println("***************************************");
- System.out.println("** 1.)DAVAO CITY | Php500 | "+available[1]+" **");
- System.out.println("** 2.)PANABO CITY | Php400 | "+available[2]+" **");
- System.out.println("** 3.)TAGUM CITY | Php300 | "+available[3]+" **");
- System.out.println("** 4.)NABUNTURAN | Php200 | "+available[4]+" **");
- System.out.println("** 5.)COMPOSTELA | Php100 | "+available[5]+" **");
- System.out.println("***************************************");
- System.out.println("***************************************\n");
- System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
- if((available[1]==0)&&(available[2]==0)&&(available[3]==0)&&(available[4]==0)&&(available[5]==0)){
- System.out.println("Sorry, We don't have available seats for all Destination!");
- x=0;
- }
- //inputing of Passenger's Name//
- else{
- for(x=1; x==1;){
- System.out.print("\nENTER PASSENGER'S NAME: ");
- ticketS[z][0] = in.readLine();
- x=0;
- //if Passenger's Name already used, display error and go back to Inputing//
- for(int l=0; l<z; l++){
- if(ticketS[l][0].equalsIgnoreCase(ticketS[z][0])){
- System.out.println("Sorry, Passenger's name have already used!");
- x=1;
- }
- }
- }
- //inputing of Destination//
- //integers Only [1-5]//
- for(x=1; x==1;){
- System.out.print("ENTER DESTINATION: ");
- to = Integer.parseInt(in.readLine());
- //if Inputed integers are "<1" or ">5", display error and go back to Inputing//
- if(to<1 || to>5){
- System.out.println("Invalid Input!");
- x=1;
- }
- //if available seat is eqaul to "Zero", display error and go back to Inputing//
- for(int d=1; d<=5; d++){
- if(to==d){
- if(available[to]==0){
- System.out.println("Sorry, We don't have available seat!");
- x=1;
- }
- x=0;
- }
- }
- }
- //convert the integer to string//
- String dest[] = { " ", "DAVAO CITY", "PANABO CITY", "TAGUM CITY", "NABUNTURAN", "COMPOSTELA"};
- double fare[] = { 0,500,400,300,200,100};
- //converted integer to string, transfer to storage array//
- ticketS[z][1] = dest[to];
- ticketD[z][0] = fare[to];
- //inputing for Number of Passenger's//
- for(x=1; x==1;){
- System.out.print("HOW MANY PASSENGERS ARE YOU?: ");
- ticketI[z][0] = Integer.parseInt(in.readLine());
- //subtract the available seat by the the number inputed//
- for(int p=1; p<=5; p++){
- if(to==p){
- print=1;
- available[to] = available[to]-ticketI[z][0];
- //if the subtracted available seat is "<0", display error//
- //add the inputed number to the subtracted seat, to back the original seat//
- //display the available seat and back to the inputing//
- if(available[to]<0){
- System.out.print("Sorry, We don't have seat available for " +ticketI[z][0] +" person\n");
- available[to] = available[to]+ticketI[z][0];
- System.out.print("We only have " +available[to] +" seat available\n");
- x=1;
- print=0;
- }
- else{
- x=0;
- }
- }
- }
- }
- //inputing for Number of Discounted Passenger's//
- for(x=1;x==1;){
- System.out.print("HOW MANY PASSENGERS HAVE DISCOUNT?: ");
- ticketI[z][1] = Integer.parseInt(in.readLine());
- if(ticketI[z][1]>ticketI[z][0]){
- System.out.println("Invalid Input!");
- System.out.println("No. of Passengers are only " +ticketI[z][0] +"!");
- x=1;
- }
- else{
- break;
- }
- }
- //print out of passengers details....
- if(print==1){
- System.out.println("\n***************************************");
- System.out.println("** PASSENGER'S DETAILS **");
- System.out.println("***************************************");
- System.out.println("PASSENGER'S NAME: " + ticketS[z][0]);
- System.out.println("PASSENGER'S DESTINATION : " + ticketS[z][1]);
- System.out.println("FARE PRICE: Php " + ticketD[z][0]);
- System.out.println("NO. OF PASSENGERS: " + ticketI[z][0]);
- System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[z][1]);
- System.out.println("***************************************");
- System.out.println("***************************************\n");
- ticketS[z][2]="0";
- double discount=(ticketD[z][0]-(ticketD[z][0]*0.2))*ticketI[z][1];
- ticketD[z][2]= ((ticketI[z][0]-ticketI[z][1])*ticketD[z][0])+discount;
- x=0;
- }
- z++;
- }
- }
- else if (choice.equals("3")){
- for(x=1; x==1;){
- System.out.print("ENTER PASSENGER'S NAME: ");
- search = in.readLine();
- int s=1;
- for(int b=0;b<z;b++){
- if(search.equalsIgnoreCase(ticketS[b][0])){
- System.out.println("***************************************");
- System.out.println("** PASSENGER'S DETAILS **");
- System.out.println("***************************************");
- System.out.println("PASSENGER'S NAME: " + ticketS[b][0]);
- System.out.println("PASSENGER'S DESTINATION : " + ticketS[b][1]);
- System.out.println("FARE PRICE: Php" + ticketD[b][0]);
- System.out.println("NO. OF PASSENGERS: " + ticketI[b][0]);
- System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[b][1]);
- System.out.println("***************************************");
- System.out.println("***************************************");
- s=0;
- x=0;
- if(ticketS[b][2].equals("x")){
- System.out.println("Passenger's Already Paid!");
- x=0;
- }
- else{
- ticketS[b][2]="x";
- for(x=1; x==1;){
- System.out.println("\nPASSENGER'S TOTAL FARE: Php "+ticketD[b][2]);
- System.out.print("ENTER AMOUNT TO PAY: ");
- pay[b] = Double.parseDouble(in.readLine());
- change[b]=pay[b]-ticketD[b][2];
- if(change[b]<0){
- System.out.println("Invalid Input!");
- x=1;
- }
- else{
- System.out.println("CHANGE: Php "+change[b]);
- System.out.println("");
- x=0;
- }
- }
- }
- }
- }
- if (s==1){
- System.out.println("\nPASSENGER'S NAME NOT FOUND!\n");
- for(int q=1; q==1;){
- System.out.print("Do you wish to continue with this transaction? [Y/N]: ");
- again=in.readLine();
- if(again.equalsIgnoreCase("y")){
- q=0;
- }
- else if (again.equalsIgnoreCase("n")){
- q=0;
- x=0;
- }
- else{
- System.out.println("\nInvalid input!\n");
- }
- }
- }
- }
- }
- else if (choice.equals("4")){
- for(int sx=1; sx<=3;){
- System.out.print("SEARCH PASSENGER'S NAME: ");
- search = in.readLine();
- int s=1;
- for(x=0; x<=z; x++){
- if(search.equalsIgnoreCase(ticketS[x][0])){
- System.out.println("***************************************");
- System.out.println("** PASSENGER'S DETAILS **");
- System.out.println("***************************************");
- System.out.println("PASSENGER'S NAME: " + ticketS[x][0]);
- System.out.println("PASSENGER'S DESTINATION : " + ticketS[x][1]);
- System.out.println("FARE PRICE: Php" + ticketD[x][0]);
- System.out.println("NO. OF PASSENGERS: " + ticketI[x][0]);
- System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[x][1]);
- System.out.println("TOTAL FARE PRICE: Php " + ticketD[x][2]);
- if(ticketS[x][2].equals("x")){
- System.out.println("PAY: Php " +pay[x]);
- System.out.println("CHANGE: Php " +change[x]);
- System.out.println("STATUS: PAID");
- }
- else{
- System.out.println("STATUS: NOT PAID");
- }
- System.out.println("***************************************");
- System.out.println("***************************************");
- s=0;
- sx=4;
- }
- }
- if (s==1){
- System.out.println("Passenger's Name not found!");
- sx++;
- }
- }
- }
- /* else if(choice.equals("5")){
- //CANCELL RESERVATION
- } */
- else if(choice.equals("5")) {
- end=1;
- x=0;
- System.out.println("Thank You!");
- }
- else{
- System.out.println("Invalid Input!");
- x=1;
- }
- }
- for(y=1; y==1;){
- if(end==1){
- break;
- }
- System.out.print("Do you want another transaction? [Y/N]: ");
- yn = in.readLine();
- if (yn.equalsIgnoreCase("y")){
- x=1;
- y=0;
- }
- else if (yn.equalsIgnoreCase("n")){
- System.out.println("\nThank You!!!");
- System.out.println();
- System.out.println();
- i=3;
- mm=1;
- //y=0;
- break;
- }
- else{
- System.out.println("Invalid Input!!!");
- y=1;
- }
- }
- }
- i=4;
- }
- else{
- System.out.println("\nInvalid user or password!\n");
- // i++;
- i=2;
- }
- //i=3;
- }
- break;
- case 2:
- System.out.println("\nThank You!!!");
- System.exit(0);
- break;
- }
- //main menu loop end
- // mm=1;
- System.out.println();
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement