Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.10 KB | None | 0 0
  1.  
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import java.util.InputMismatchException;
  6.  
  7.  
  8. public class busReservationFinal {
  9.  
  10. public static void main(String args[]) throws IOException {
  11. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  12. Scanner sc = new Scanner(System.in);
  13.  
  14. String user,password,yn,search = null,again,choice;
  15. int to=0,y=1,z=0,end=0,r=1, bn = 1, ab=0, g=0, mn;
  16. boolean w = true;
  17. int available[] = new int[100];
  18. int busN[] = new int[200];
  19. int ticketI[][] = new int [100][3];
  20. String Driver[] = new String[0];
  21. String Cond[] = new String[0];
  22. String Empl[] = new String[0];
  23. String Posi[] = new String[0];
  24. String ticketS[][] = new String[100][3];
  25. double ticketD[][] = new double [100][3];
  26. double pay[] = new double[20];
  27.  
  28. double change[] = new double[20];
  29.  
  30. for(int o=1; o<=5; o++){
  31. available[o]=60;
  32. }
  33.  
  34. for(int mm = 1; mm==1;){
  35. /*while(g==0) {
  36. try { */
  37. System.out.println("-MAIN MENU-");
  38. System.out.println("[0]Admin");
  39. System.out.println("[1]Staff");
  40. System.out.println("[2]Exit");
  41. System.out.print("Enter your choice: ");
  42. mn = sc.nextInt();
  43. /* break;
  44. }
  45. catch (InputMismatchException e) {
  46. System.out.println("-INVALID INPUT!-");
  47. System.out.println();
  48. sc.next();
  49. g=0;
  50. }
  51. } */
  52. switch(mn){
  53. case 0:
  54. for(int i=2;i==2;){
  55. System.out.println();
  56. System.out.println("Admin Login");
  57. System.out.print("Enter User: ");
  58. user = in.readLine();
  59. System.out.print("Enter Password: ");
  60. password = in.readLine();
  61.  
  62. if(user.equalsIgnoreCase("Admin") && password.equalsIgnoreCase("1234")){
  63.  
  64. for(int x=1; x==1;){
  65.  
  66. System.out.println("--------------------------------------------");
  67. System.out.println("| BUS RESERVATION AND TICKETING SYSTEM |");
  68. System.out.println("|------------------------------------------|");
  69. System.out.println("|[1] Bus - Driver/Conductor Details |");
  70. System.out.println("|[2] Employees |");
  71. System.out.println("|[3] Customers |");
  72. System.out.println("|[4] Destination and Fare |");
  73. System.out.println("|[5] Sales |");
  74. System.out.println("|[6] Exit |");
  75. System.out.println("|------------------------------------------|");
  76. System.out.println("--------------------------------------------\n");
  77. busN[ab] = bn;
  78. for(x=1; x==1;){
  79. for(int rr=0; rr==0;) {
  80.  
  81.  
  82. System.out.print("Enter Choice: ");
  83. int choice1 = Integer.parseInt(in.readLine());
  84. System.out.println();
  85. if(choice1<=6) {
  86. switch(choice1){
  87. //CASE 1 BUS DRIVER CONDUCTOR DETAILS
  88. case 1:
  89. for(int hh=0;hh==0;) {
  90. System.out.println("[0]view [1]add [2]edit [3]search [4]delete [5]back\n");
  91. int choice2 = Integer.parseInt(in.readLine());
  92. if(choice2<=5) {
  93. //case 1 case 0 view
  94.  
  95. switch(choice2){
  96. case 0:
  97. System.out.println("[View]");
  98. System.out.println("**********************************************************");
  99. System.out.println("**\tBUS NO.\t|\tDRIVER\t|\tCONDUCTOR\t");
  100. System.out.println("**********************************************************");
  101.  
  102. for(int a = 0; a < Driver.length; a++){
  103. if(Driver[a] == null)
  104. Driver[a]="";
  105. if(Cond[a]==null)
  106. Cond[a]="";
  107.  
  108. System.out.println("**\t"+ busN[a]+"\t|\t" + Driver[a] +"\t| "+Cond[a]);
  109. }
  110. System.out.println("**********************************************************");
  111. System.out.println("**********************************************************\n");
  112. rr=1;
  113. break;
  114.  
  115. //case 1 case 1 add
  116. case 1:
  117.  
  118.  
  119. System.out.println("[Add]");
  120. System.out.println("Number of bus to add: ");
  121. ArrayList<String> myList = new ArrayList<String>(Arrays.asList(Driver));
  122. ArrayList<String> myListt = new ArrayList<String>(Arrays.asList(Cond));
  123. int size = Integer.parseInt(in.readLine());
  124.  
  125. System.out.println("Enter Bus Driver and Conductor Name:");
  126. for(int gg = 0; gg < size; gg++){
  127. System.out.println();
  128. System.out.println("Driver: ");
  129. String element1 = in.readLine().toUpperCase();
  130. System.out.println("Conductor: ");
  131. String element2 = in.readLine().toUpperCase();
  132. myList.add(element1);
  133. myListt.add(element2);
  134. }
  135. Driver = myList.toArray(Driver);
  136. Cond = myListt.toArray(Cond);
  137. System.out.println("Successfully Added");
  138. rr=1;
  139. break;
  140.  
  141. //case 1 case 2 edit
  142. case 2:
  143. System.out.println("[Edit]");
  144. do {
  145. System.out.println("Enter Bus Number:");
  146. choice1 = Integer.parseInt(in.readLine());
  147.  
  148. int s = 1;
  149.  
  150. for(int ss = 0; ss < Driver.length; ss++) {
  151.  
  152. if(choice1==busN[ss]) {
  153.  
  154. while(w==true) {
  155. System.out.println("[0] Driver");
  156. System.out.println("[1] Conductor");
  157. choice2 = Integer.parseInt(in.readLine());
  158. if(choice2==0) {
  159. System.out.println("Enter to edit: ");
  160. search = in.readLine();
  161. Driver[ss] = search.toUpperCase();
  162. System.out.println("Edit succesful.");
  163. w=false;
  164. }
  165. else if(choice2==1){
  166. System.out.println("Enter to edit: ");
  167. search = in.readLine();
  168. Cond[ss] = search.toUpperCase();
  169. System.out.println("Edit succesful.");
  170. w=false;
  171. }
  172. else {
  173. System.out.println("Invalid Input.");
  174. w = true;
  175. }
  176. s=0;
  177. }
  178. }
  179.  
  180. }
  181. if (s==1){
  182. System.out.println("Bus Number Not Found!");
  183. g=1;
  184. }
  185. else{
  186. g=0;
  187. }
  188. x=0;
  189. }while(g==1);
  190. rr=1;
  191. break;
  192.  
  193. //case 1 case 3 search
  194. case 3:
  195. System.out.println("[Search]");
  196. System.out.println("Enter a name to search: ");
  197. search = in.readLine();
  198. for(int ss = 0; ss < Driver.length; ss++){
  199. if(search.equalsIgnoreCase(Driver[ss]) || search.equalsIgnoreCase(Cond[ss])){
  200. System.out.println("******************************************");
  201. System.out.println("** BUS NO. | DRIVER | CONDUCTOR **");
  202. System.out.println("***************************************");
  203. System.out.println("** " + busN[ss] + " | " + Driver[ss] + " | " +Cond[ss]+" **");
  204.  
  205. System.out.println("******************************************");
  206. System.out.println("******************************************\n");
  207. }
  208. }
  209. rr=1;
  210. break;
  211. case 4:
  212.  
  213. System.out.println("[Delete]");
  214. ArrayList<String> myList1 = new ArrayList<String>(Arrays.asList(Driver));
  215. ArrayList<String> myListt2 = new ArrayList<String>(Arrays.asList(Cond));
  216.  
  217. System.out.println("[0]Driver");
  218. System.out.println("[1]Conductor");
  219. choice1 = Integer.parseInt(in.readLine());
  220.  
  221. if(choice1==0) {
  222. System.out.println("Enter name: ");
  223. String element1 = in.readLine();
  224. String element11 = element1.toUpperCase();
  225. myList1.remove(element11);
  226. Driver = myList1.toArray(Driver);
  227. System.out.println("Successfully Deleted");
  228. }
  229. else {
  230. System.out.println("Enter name: ");
  231. String element2 = in.readLine();
  232. String element22=element2.toUpperCase();
  233. myListt2.remove(element22);
  234. Cond = myListt2.toArray(Cond);
  235. System.out.println("Successfully Deleted");
  236. }
  237. rr=1;
  238. break;
  239.  
  240.  
  241.  
  242.  
  243. case 5:
  244. rr=1;
  245. break;
  246. }
  247. hh=1;
  248. }
  249. else {
  250. System.out.println("INVALID INPUT");
  251. hh = 0;
  252.  
  253. }
  254.  
  255.  
  256. }
  257.  
  258.  
  259.  
  260.  
  261. break;
  262.  
  263.  
  264. //CASE 2 EMPLOYEES
  265. case 2:
  266. System.out.println("[Employees]");
  267. for(int nn = 0; nn==0;) {
  268. System.out.println("[0]view [1]add [2]edit [3]search [4]delete [5]back\n");
  269. int choice3 = Integer.parseInt(in.readLine());
  270. if(choice3<=5) {
  271. switch(choice3){
  272. //case 2 employees case 0 view
  273. case 0:
  274. System.out.println("[View]");
  275. System.out.println("**********************************************************");
  276. System.out.println("** Employee's Name | Position **");
  277. System.out.println("**********************************************************");
  278. for(int a = 0; a < Empl.length; a++){
  279. if(Empl[a] == null)
  280. Empl[a]="";
  281. if(Posi[a]==null)
  282. Posi[a]="";
  283.  
  284. System.out.println("**\t" + Empl[a] +"\t|\t"+ Posi[a]+"\t**");
  285.  
  286. }
  287. System.out.println("******************************************");
  288. System.out.println("******************************************\n");
  289. rr=1;
  290. break;
  291.  
  292. //case 2 employees case 1 add
  293. case 1:
  294. System.out.println("[Add]");
  295.  
  296. System.out.println("Number of Employee's to add: ");
  297. ArrayList<String> myList1 = new ArrayList<String>(Arrays.asList(Empl));
  298. ArrayList<String> myList2 = new ArrayList<String>(Arrays.asList(Posi));
  299. int size = Integer.parseInt(in.readLine());
  300.  
  301. System.out.println("Enter Employee's Name and Position:");
  302. for(int gg = 0; gg < size; gg++){
  303. System.out.println();
  304. System.out.println("Employee: ");
  305. String element1 = in.readLine();
  306. System.out.println("Position: ");
  307. String element2 = in.readLine();
  308. myList1.add(element1);
  309. myList2.add(element2);
  310. }
  311.  
  312. Empl = myList1.toArray(Empl);
  313. Posi = myList2.toArray(Posi);
  314. System.out.println("Successfully Added");
  315. rr=1;
  316. mm=3;
  317. break;
  318.  
  319. //case 2 employees case 2 edit
  320. case 2:
  321. while(w==true) {
  322. System.out.println("[Edit]");
  323. System.out.println("[0] Employee");
  324. System.out.println("[1] Position");
  325. choice1 = Integer.parseInt(in.readLine());
  326.  
  327.  
  328. if(choice1==0){
  329. while(w==true) {
  330. System.out.println("Search a name to edit: ");
  331. search = in.readLine();
  332. for(int ss = 0; ss < Empl.length; ss++){
  333. if(search.equalsIgnoreCase(Empl[ss])){
  334. System.out.println("******************************************");
  335. System.out.println("** Employee | Position **");
  336. System.out.println("***************************************");
  337. System.out.println("** " + Empl[ss] + " | " +Posi[ss]+" **");
  338.  
  339. System.out.println("******************************************");
  340. System.out.println("******************************************\n");
  341.  
  342. System.out.println("Edit to: ");
  343. search = in.readLine();
  344. Empl[ss] = search;
  345.  
  346. System.out.println("Edit Successful!");
  347. System.out.println("******************************************");
  348. System.out.println("** Employee | Position **");
  349. System.out.println("***************************************");
  350. System.out.println("** " + Empl[ss] + " | " +Posi[ss]+" **");
  351.  
  352. System.out.println("******************************************");
  353. System.out.println("******************************************\n");
  354. w = false;
  355. break;
  356. }
  357. else {
  358. System.out.println("INVALID INPUT");
  359. w= true;
  360. }
  361.  
  362. }
  363. }
  364. }
  365. if (choice1==1){
  366. while(w==true) {
  367. System.out.println("Search a name to edit: ");
  368. String search1=in.readLine();
  369. for(int aa=0; aa<Posi.length; aa++){
  370. if(search1.equalsIgnoreCase(Posi[aa])){
  371. System.out.println("******************************************");
  372. System.out.println("** Employee | Position **");
  373. System.out.println("***************************************");
  374. System.out.println("** " + Empl[aa] + " | " +Posi[aa]+" **");
  375.  
  376. System.out.println("******************************************");
  377. System.out.println("******************************************\n");
  378.  
  379. System.out.println("Edit to: ");
  380. search1 = in.readLine();
  381. Posi[aa] = search1;
  382.  
  383. System.out.println("Edit Successful!");
  384. System.out.println("******************************************");
  385. System.out.println("** Employee | Position **");
  386. System.out.println("***************************************");
  387. System.out.println("** " + Empl[aa] + " | " +Posi[aa]+" **");
  388.  
  389. System.out.println("******************************************");
  390. System.out.println("******************************************\n");
  391. w= false;
  392. break;
  393. }
  394. else {
  395. System.out.println("No result for " + search);
  396. w= true;
  397. }
  398. }
  399. }
  400. }
  401. if(choice1<0 || choice1>6) {
  402. System.out.println("INVALID INPUT");
  403. w=true;
  404. }
  405. }
  406. rr=1;
  407. break;
  408.  
  409. //case 2 employees case 3 search
  410. case 3:
  411. System.out.println("[Search]");
  412.  
  413. for(int aaa=0; aaa==0;) {
  414. System.out.println("Enter a name to search: ");
  415. search = in.readLine();
  416. for(int ss = 0; ss < Empl.length; ss++){
  417. if(search.equalsIgnoreCase(Empl[ss]) || search.equalsIgnoreCase(Posi[ss])){
  418. System.out.println("******************************************");
  419. System.out.println("** Employee | Position **");
  420. System.out.println("***************************************");
  421. System.out.println("** " + Empl[ss] + " | " +Posi[ss]+" **");
  422. System.out.println("******************************************");
  423. System.out.println("******************************************\n");
  424. aaa=1;
  425. }
  426. else {
  427. System.out.println("Name not found.");
  428. aaa=0;
  429.  
  430. }
  431. }
  432. }
  433. rr=1;
  434. break;
  435.  
  436. //case 2 employees case 4 delete
  437. case 4:
  438.  
  439. System.out.println("[Delete]");
  440. System.out.println("Number of employees to remove: ");
  441. ArrayList<String> myList3 = new ArrayList<String>(Arrays.asList(Empl));
  442. ArrayList<String> myList4 = new ArrayList<String>(Arrays.asList(Posi));
  443. int size1 = Integer.parseInt(in.readLine());
  444.  
  445. for(int yy=0; yy==0;) {
  446. System.out.println("Enter employee name: ");
  447. for(int gg = 0; gg < size1; gg++){
  448. System.out.println();
  449. System.out.println("Employee: ");
  450. String element1 = in.readLine();
  451. if(element1.equalsIgnoreCase(Empl[gg])) {
  452. //System.out.println("Position: ");
  453. //String element2 = in.readLine();
  454. myList3.remove(element1);
  455. myList4.remove(Posi[gg]);
  456. yy=1;
  457. }
  458. else {
  459. System.out.println("Name not found.");
  460. yy=0;
  461. }
  462. }
  463. }
  464. Empl = myList3.toArray(Empl);
  465. Posi = myList4.toArray(Posi);
  466. System.out.println("Successfully Deleted");
  467. rr=1;
  468.  
  469. break;
  470.  
  471.  
  472.  
  473. //case 2 employees case 5 back
  474. case 5:
  475. x = 1;
  476. rr=1;
  477. break;
  478. }
  479. break;
  480.  
  481. }
  482. else {
  483. System.out.println("INVALID INPUT");
  484. nn = 0;
  485. }
  486. }
  487. break;
  488.  
  489. //CUSTOMERS
  490. case 3:
  491. System.out.println("[Customers]");
  492. System.out.println("[0]view [1]search\n");
  493. int choice4 = Integer.parseInt(in.readLine());
  494.  
  495. switch(choice4){
  496. case 0:
  497. System.out.println("[View]");
  498. System.out.println("**********************************************************");
  499. System.out.println("** Customer's Name | Destination **");
  500. System.out.println("**********************************************************");
  501.  
  502. for(int a = 0; a <z ; a++){
  503. System.out.println("**\t"+ ticketS[a][0] +"\t\t**\t"+ticketS[a][1]);
  504.  
  505. }
  506. //z++;
  507.  
  508. System.out.println("**********************************************************");
  509. System.out.println("**********************************************************\n");
  510. rr=1;
  511. mm=3;
  512. break;
  513.  
  514. case 1:
  515. // System.out.println("Search Customer's Name: ");
  516. // search = in.readLine();
  517. // Search
  518. for(int sx=1; sx<=3;){
  519.  
  520. System.out.print("SEARCH PASSENGER'S NAME: ");
  521. search = in.readLine();
  522.  
  523. int s=1;
  524. for(x=0; x<=z; x++){
  525. if(search.equalsIgnoreCase(ticketS[x][0])){
  526. System.out.println("***************************************");
  527. System.out.println("** PASSENGER'S DETAILS **");
  528. System.out.println("***************************************");
  529. System.out.println("PASSENGER'S NAME: " + ticketS[x][0]);
  530. System.out.println("PASSENGER'S DESTINATION : " + ticketS[x][1]);
  531. System.out.println("FARE PRICE: Php" + ticketD[x][0]);
  532. System.out.println("NO. OF PASSENGERS: " + ticketI[x][0]);
  533. System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[x][1]);
  534. System.out.println("TOTAL FARE PRICE: Php " + ticketD[x][2]);
  535. if(ticketS[x][2].equals("x")){
  536. System.out.println("PAY: Php " +pay[x]);
  537. System.out.println("CHANGE: Php " +change[x]);
  538. System.out.println("STATUS: PAID");
  539. }
  540. else{
  541. System.out.println("STATUS: NOT PAID");
  542. }
  543. System.out.println("***************************************");
  544. System.out.println("***************************************");
  545. s=0;
  546. sx=4;
  547. }
  548.  
  549. }
  550. if (s==1){
  551. System.out.println("Passenger's Name not found!");
  552. sx=1;
  553. }
  554. }
  555. rr=1;
  556. mm=3;
  557.  
  558.  
  559. }
  560. mm=3;
  561. rr=1;
  562. break;
  563.  
  564.  
  565.  
  566. case 4:
  567. System.out.println("[Destination and Fare]");
  568. System.out.println("***************************************");
  569. System.out.println("** DESTINATION | FARE | SEAT **");
  570. System.out.println("***************************************");
  571. System.out.println("** 1.)DAVAO CITY | Php500 | "+available[1]+" **");
  572. System.out.println("** 2.)PANABO CITY | Php400 | "+available[2]+" **");
  573. System.out.println("** 3.)TAGUM CITY | Php300 | "+available[3]+" **");
  574. System.out.println("** 4.)NABUNTURAN | Php200 | "+available[4]+" **");
  575. System.out.println("** 5.)COMPOSTELA | Php100 | "+available[5]+" **");
  576. System.out.println("***************************************");
  577. System.out.println("***************************************\n");
  578. System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
  579. rr=1;
  580. break;
  581. case 5:
  582. for(int ss = 0; ss==0;) {
  583. System.out.println("[Sales]");
  584. System.out.println("[0]Daily");
  585. System.out.println("[1]Weekly");
  586. System.out.println("[2]Monthly");
  587. System.out.println("Enter choice: ");
  588. choice1 = sc.nextInt();
  589. if(choice1==0) {
  590. int sum = 0;
  591. for(int b = 0; b < z; b++) {
  592. sum+=ticketD[b][2];
  593. }
  594. System.out.println("[Daily]");
  595. System.out.println("DAYS"+"\t"+"|"+"\t"+"DAILY SALES");
  596. System.out.println("-----------------------------------------------------");
  597.  
  598. String days[] = {"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
  599. System.out.println(days [1]+"\t\t"+"|\t"+sum);
  600. System.out.println(days [2]+"\t\t"+"|\t");
  601. System.out.println(days [3]+"\t"+"|\t");
  602. System.out.println(days [4]+"\t"+"|\t");
  603. System.out.println(days [5]+"\t\t"+"|\t");
  604. System.out.println(days [6]+"\t"+"|\t");
  605. System.out.println(days [7]+"\t\t"+"|\t");
  606. System.out.println("-----------------------------------------------------");
  607. System.out.println("TOTAL"+"\t\t"+ sum);
  608. System.out.println("-----------------------------------------------------");
  609. System.out.println();
  610. ss=1;
  611. }
  612.  
  613.  
  614. else if(choice1==1) {
  615. int sum = 0;
  616. for(int b = 0; b < z; b++) {
  617. sum+=ticketD[b][2];
  618. }
  619. System.out.println ("- WEEKLY SALES REPORT -");
  620. System.out.println("-----------------------------------------------------");
  621. System.out.println("WEEK"+"\t"+"|"+"\t\t"+"WEEKLY SALES");
  622. System.out.println("-----------------------------------------------------");
  623. String week[] = {"","Week 1","Week 2","Week 3","Week 4"};
  624. System.out.println(week [1]+"\t"+"|\t");
  625. System.out.println(week [2]+"\t"+"|\t"+sum);
  626. System.out.println(week [3]+"\t"+"|\t");
  627. System.out.println(week [4]+"\t"+"|\t");
  628. System.out.println("-----------------------------------------------------");
  629. System.out.println("TOTAL"+"\t\t"+sum);
  630. System.out.println("-----------------------------------------------------");
  631. System.out.println();
  632. ss=1;
  633. }
  634. else if(choice1==2) {
  635. int sum = 0;
  636. for(int b = 0; b < z; b++) {
  637. sum+=ticketD[b][2];
  638. }
  639. System.out.println ("- MONTHLY SALES REPORT -");
  640. System.out.println("-----------------------------------------------------");
  641. System.out.println("MONTH"+"\t\t"+"|"+"\t\t"+"MONTHLY SALES");
  642. System.out.println("-----------------------------------------------------");
  643. String month[] = {"","January","February","March","April","May","June","July","August","September","October","November","December"};
  644. System.out.println(month [1]+"\t\t"+"|\t");
  645. System.out.println(month [2]+"\t"+"|");
  646. System.out.println(month [3]+"\t\t"+"|");
  647. System.out.println(month [4]+"\t\t"+"|");
  648. System.out.println(month [5]+"\t\t"+"|");
  649. System.out.println(month [6]+"\t\t"+"|");
  650. System.out.println(month [7]+"\t\t"+"|");
  651. System.out.println(month [8]+"\t\t"+"|");
  652. System.out.println(month [9]+"\t"+"|");
  653. System.out.println(month [10]+"\t\t"+"|");
  654. System.out.println(month [11]+"\t"+"|");
  655. System.out.println(month [12]+"\t"+"|\t"+sum);
  656. System.out.println("-----------------------------------------------------");
  657. System.out.println("TOTAL"+"\t\t"+"|\t\t"+sum);
  658. System.out.println("-----------------------------------------------------");
  659. System.out.println();
  660. ss=1;
  661. }
  662. else{
  663. System.out.println("INVALID INPUT");
  664. ss=0;
  665. }
  666.  
  667. }mm=0;
  668. rr=1;
  669. break;
  670. case 6:
  671. System.out.println("Exit...");
  672.  
  673. rr=1;
  674. break;
  675. }
  676. }
  677. else {
  678. System.out.println("INVALID INPUT");
  679. rr=0;
  680. }
  681. }
  682. x=4;
  683. }
  684. bn++;
  685. ab++;
  686. r++;
  687.  
  688. for(y=1; y==1;){
  689.  
  690. if(end==1){
  691. break;
  692. }
  693.  
  694.  
  695. System.out.print("Do you want another transaction? [Y/N]: ");
  696. yn = in.readLine();
  697.  
  698. if (yn.equalsIgnoreCase("y")){
  699. x=1;
  700. y=0;
  701. }
  702. else if (yn.equalsIgnoreCase("n")){
  703. System.out.println("\nThank You!!!");
  704. System.out.println();
  705. System.out.println();
  706. i=3;
  707. mm=1;
  708. break;
  709. }
  710. else{
  711. System.out.println("Invalid Input!!!");
  712. y=1;
  713. }
  714. }
  715. }
  716. i=4;
  717. }
  718.  
  719. else{
  720. System.out.println("\nInvalid user or password!\n");
  721. i=2;
  722. }
  723. }
  724.  
  725. break;
  726.  
  727.  
  728.  
  729.  
  730.  
  731. /////////////////////////////////////////////////////////
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738. //STAFF
  739. case 1:
  740. // for(int i=1;i<10000;){
  741. for(int i=2;i==2;){
  742. System.out.println();
  743. System.out.println("Staff Login");
  744. System.out.print("Enter User: ");
  745. user = in.readLine();
  746. System.out.print("Enter Password: ");
  747. password = in.readLine();
  748.  
  749. //"available[]" is the SEAT AVAILABLE//
  750. //store 60 seats every destination [1-5]//
  751.  
  752.  
  753. //if user and password are correct proceed to MAIN MENU//
  754. if(user.equalsIgnoreCase("Staff") && password.equalsIgnoreCase("1234")){
  755.  
  756. for(int x=1; x==1;){
  757. //the MAIN MENU//
  758. System.out.println("--------------------------------------------");
  759. System.out.println("| BUS RESERVATION AND TICKETING SYSTEM |");
  760. System.out.println("|------------------------------------------|");
  761. System.out.println("|[1] Destination |");
  762. System.out.println("|[2] Passengers |");
  763. System.out.println("|[3] Billing |");
  764. System.out.println("|[4] View |");
  765. System.out.println("|[5] Exit |");
  766. System.out.println("|------------------------------------------|");
  767. System.out.println("--------------------------------------------\n");
  768.  
  769. for(x=1; x==1;){
  770. System.out.print("Enter Choice: ");
  771. choice=in.readLine();
  772. System.out.println();
  773.  
  774. //if CHOICE is "1" display the DESTINATION//
  775. if (choice.equals("1")){
  776. //the DESTINATION DETAILS//
  777. //display the "Destination", every destination "Fare", and the "Seat" available//
  778. System.out.println("***************************************");
  779. System.out.println("** DESTINATION | FARE | SEAT **");
  780. System.out.println("***************************************");
  781. System.out.println("** 1.)DAVAO CITY | Php500 | "+available[1]+" **");
  782. System.out.println("** 2.)PANABO CITY | Php400 | "+available[2]+" **");
  783. System.out.println("** 3.)TAGUM CITY | Php300 | "+available[3]+" **");
  784. System.out.println("** 4.)NABUNTURAN | Php200 | "+available[4]+" **");
  785. System.out.println("** 5.)COMPOSTELA | Php100 | "+available[5]+" **");
  786. System.out.println("***************************************");
  787. System.out.println("***************************************\n");
  788. System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
  789. x=0;
  790. }
  791.  
  792. //if CHOICE is "2" proceed to Ticket Booking//
  793. else if (choice.equals("2")){
  794. int print=1;
  795.  
  796.  
  797.  
  798. //display first the Destination Details//
  799. System.out.println("***************************************");
  800. System.out.println("** DESTINATION | FARE | SEAT **");
  801. System.out.println("***************************************");
  802. System.out.println("** 1.)DAVAO CITY | Php500 | "+available[1]+" **");
  803. System.out.println("** 2.)PANABO CITY | Php400 | "+available[2]+" **");
  804. System.out.println("** 3.)TAGUM CITY | Php300 | "+available[3]+" **");
  805. System.out.println("** 4.)NABUNTURAN | Php200 | "+available[4]+" **");
  806. System.out.println("** 5.)COMPOSTELA | Php100 | "+available[5]+" **");
  807. System.out.println("***************************************");
  808. System.out.println("***************************************\n");
  809. System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
  810.  
  811. if((available[1]==0)&&(available[2]==0)&&(available[3]==0)&&(available[4]==0)&&(available[5]==0)){
  812. System.out.println("Sorry, We don't have available seats for all Destination!");
  813. x=0;
  814.  
  815. }
  816.  
  817.  
  818.  
  819. //inputing of Passenger's Name//
  820. else{
  821. for(x=1; x==1;){
  822. System.out.print("\nENTER PASSENGER'S NAME: ");
  823. ticketS[z][0] = in.readLine();
  824.  
  825.  
  826. x=0;
  827.  
  828. //if Passenger's Name already used, display error and go back to Inputing//
  829. for(int l=0; l<z; l++){
  830. if(ticketS[l][0].equalsIgnoreCase(ticketS[z][0])){
  831. System.out.println("Sorry, Passenger's name have already used!");
  832. x=1;
  833. }
  834. }
  835. }
  836.  
  837. //inputing of Destination//
  838. //integers Only [1-5]//
  839. for(x=1; x==1;){
  840. System.out.print("ENTER DESTINATION: ");
  841. to = Integer.parseInt(in.readLine());
  842.  
  843. //if Inputed integers are "<1" or ">5", display error and go back to Inputing//
  844. if(to<1 || to>5){
  845. System.out.println("Invalid Input!");
  846. x=1;
  847. }
  848. //if available seat is eqaul to "Zero", display error and go back to Inputing//
  849. for(int d=1; d<=5; d++){
  850. if(to==d){
  851. if(available[to]==0){
  852. System.out.println("Sorry, We don't have available seat!");
  853. x=1;
  854. }
  855. x=0;
  856. }
  857. }
  858. }
  859.  
  860. //convert the integer to string//
  861. String dest[] = { " ", "DAVAO CITY", "PANABO CITY", "TAGUM CITY", "NABUNTURAN", "COMPOSTELA"};
  862. double fare[] = { 0,500,400,300,200,100};
  863.  
  864. //converted integer to string, transfer to storage array//
  865. ticketS[z][1] = dest[to];
  866. ticketD[z][0] = fare[to];
  867.  
  868. //inputing for Number of Passenger's//
  869. for(x=1; x==1;){
  870. System.out.print("HOW MANY PASSENGERS ARE YOU?: ");
  871. ticketI[z][0] = Integer.parseInt(in.readLine());
  872.  
  873. //subtract the available seat by the the number inputed//
  874. for(int p=1; p<=5; p++){
  875. if(to==p){
  876. print=1;
  877. available[to] = available[to]-ticketI[z][0];
  878.  
  879. //if the subtracted available seat is "<0", display error//
  880. //add the inputed number to the subtracted seat, to back the original seat//
  881. //display the available seat and back to the inputing//
  882. if(available[to]<0){
  883. System.out.print("Sorry, We don't have seat available for " +ticketI[z][0] +" person\n");
  884. available[to] = available[to]+ticketI[z][0];
  885. System.out.print("We only have " +available[to] +" seat available\n");
  886. x=1;
  887. print=0;
  888. }
  889. else{
  890. x=0;
  891. }
  892. }
  893. }
  894.  
  895. }
  896.  
  897. //inputing for Number of Discounted Passenger's//
  898. for(x=1;x==1;){
  899. System.out.print("HOW MANY PASSENGERS HAVE DISCOUNT?: ");
  900. ticketI[z][1] = Integer.parseInt(in.readLine());
  901.  
  902. if(ticketI[z][1]>ticketI[z][0]){
  903.  
  904. System.out.println("Invalid Input!");
  905. System.out.println("No. of Passengers are only " +ticketI[z][0] +"!");
  906. x=1;
  907. }
  908. else{
  909. break;
  910. }
  911. }
  912.  
  913.  
  914. //print out of passengers details....
  915. if(print==1){
  916. System.out.println("\n***************************************");
  917. System.out.println("** PASSENGER'S DETAILS **");
  918. System.out.println("***************************************");
  919. System.out.println("PASSENGER'S NAME: " + ticketS[z][0]);
  920. System.out.println("PASSENGER'S DESTINATION : " + ticketS[z][1]);
  921. System.out.println("FARE PRICE: Php " + ticketD[z][0]);
  922. System.out.println("NO. OF PASSENGERS: " + ticketI[z][0]);
  923. System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[z][1]);
  924. System.out.println("***************************************");
  925. System.out.println("***************************************\n");
  926. ticketS[z][2]="0";
  927. double discount=(ticketD[z][0]-(ticketD[z][0]*0.2))*ticketI[z][1];
  928. ticketD[z][2]= ((ticketI[z][0]-ticketI[z][1])*ticketD[z][0])+discount;
  929. x=0;
  930. }
  931. z++;
  932. }
  933. }
  934.  
  935. else if (choice.equals("3")){
  936.  
  937.  
  938. for(x=1; x==1;){
  939.  
  940. System.out.print("ENTER PASSENGER'S NAME: ");
  941. search = in.readLine();
  942.  
  943.  
  944. int s=1;
  945. for(int b=0;b<z;b++){
  946. if(search.equalsIgnoreCase(ticketS[b][0])){
  947. System.out.println("***************************************");
  948. System.out.println("** PASSENGER'S DETAILS **");
  949. System.out.println("***************************************");
  950. System.out.println("PASSENGER'S NAME: " + ticketS[b][0]);
  951. System.out.println("PASSENGER'S DESTINATION : " + ticketS[b][1]);
  952. System.out.println("FARE PRICE: Php" + ticketD[b][0]);
  953. System.out.println("NO. OF PASSENGERS: " + ticketI[b][0]);
  954. System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[b][1]);
  955. System.out.println("***************************************");
  956. System.out.println("***************************************");
  957. s=0;
  958. x=0;
  959.  
  960. if(ticketS[b][2].equals("x")){
  961. System.out.println("Passenger's Already Paid!");
  962. x=0;
  963. }
  964. else{
  965. ticketS[b][2]="x";
  966.  
  967.  
  968. for(x=1; x==1;){
  969. System.out.println("\nPASSENGER'S TOTAL FARE: Php "+ticketD[b][2]);
  970. System.out.print("ENTER AMOUNT TO PAY: ");
  971. pay[b] = Double.parseDouble(in.readLine());
  972. change[b]=pay[b]-ticketD[b][2];
  973.  
  974. if(change[b]<0){
  975. System.out.println("Invalid Input!");
  976. x=1;
  977. }
  978. else{
  979. System.out.println("CHANGE: Php "+change[b]);
  980. System.out.println("");
  981. x=0;
  982. }
  983. }
  984. }
  985. }
  986. }
  987. if (s==1){
  988. System.out.println("\nPASSENGER'S NAME NOT FOUND!\n");
  989. for(int q=1; q==1;){
  990.  
  991. System.out.print("Do you wish to continue with this transaction? [Y/N]: ");
  992. again=in.readLine();
  993.  
  994. if(again.equalsIgnoreCase("y")){
  995. q=0;
  996. }
  997. else if (again.equalsIgnoreCase("n")){
  998. q=0;
  999. x=0;
  1000.  
  1001. }
  1002. else{
  1003. System.out.println("\nInvalid input!\n");
  1004. }
  1005.  
  1006.  
  1007. }
  1008. }
  1009. }
  1010.  
  1011. }
  1012.  
  1013. else if (choice.equals("4")){
  1014.  
  1015.  
  1016. for(int sx=1; sx<=3;){
  1017. System.out.print("SEARCH PASSENGER'S NAME: ");
  1018. search = in.readLine();
  1019.  
  1020. int s=1;
  1021. for(x=0; x<=z; x++){
  1022. if(search.equalsIgnoreCase(ticketS[x][0])){
  1023. System.out.println("***************************************");
  1024. System.out.println("** PASSENGER'S DETAILS **");
  1025. System.out.println("***************************************");
  1026. System.out.println("PASSENGER'S NAME: " + ticketS[x][0]);
  1027. System.out.println("PASSENGER'S DESTINATION : " + ticketS[x][1]);
  1028. System.out.println("FARE PRICE: Php" + ticketD[x][0]);
  1029. System.out.println("NO. OF PASSENGERS: " + ticketI[x][0]);
  1030. System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[x][1]);
  1031. System.out.println("TOTAL FARE PRICE: Php " + ticketD[x][2]);
  1032. if(ticketS[x][2].equals("x")){
  1033. System.out.println("PAY: Php " +pay[x]);
  1034. System.out.println("CHANGE: Php " +change[x]);
  1035. System.out.println("STATUS: PAID");
  1036. }
  1037. else{
  1038. System.out.println("STATUS: NOT PAID");
  1039. }
  1040. System.out.println("***************************************");
  1041. System.out.println("***************************************");
  1042. s=0;
  1043. sx=4;
  1044. }
  1045. }
  1046.  
  1047.  
  1048. if (s==1){
  1049. System.out.println("Passenger's Name not found!");
  1050. sx++;
  1051. }
  1052.  
  1053. }
  1054. }
  1055.  
  1056. /* else if(choice.equals("5")){
  1057. //CANCELL RESERVATION
  1058.  
  1059. } */
  1060.  
  1061. else if(choice.equals("5")) {
  1062. end=1;
  1063. x=0;
  1064. System.out.println("Thank You!");
  1065.  
  1066. }
  1067.  
  1068. else{
  1069. System.out.println("Invalid Input!");
  1070. x=1;
  1071. }
  1072. }
  1073.  
  1074. for(y=1; y==1;){
  1075. if(end==1){
  1076. break;
  1077. }
  1078. System.out.print("Do you want another transaction? [Y/N]: ");
  1079. yn = in.readLine();
  1080.  
  1081. if (yn.equalsIgnoreCase("y")){
  1082. x=1;
  1083. y=0;
  1084. }
  1085. else if (yn.equalsIgnoreCase("n")){
  1086. System.out.println("\nThank You!!!");
  1087. System.out.println();
  1088. System.out.println();
  1089. i=3;
  1090. mm=1;
  1091. //y=0;
  1092. break;
  1093. }
  1094.  
  1095. else{
  1096. System.out.println("Invalid Input!!!");
  1097. y=1;
  1098. }
  1099.  
  1100. }
  1101. }
  1102. i=4;
  1103. }
  1104.  
  1105. else{
  1106. System.out.println("\nInvalid user or password!\n");
  1107. // i++;
  1108. i=2;
  1109. }
  1110.  
  1111. //i=3;
  1112. }
  1113.  
  1114. break;
  1115.  
  1116. case 2:
  1117. System.out.println("\nThank You!!!");
  1118. System.exit(0);
  1119. break;
  1120. }
  1121.  
  1122. //main menu loop end
  1123. // mm=1;
  1124.  
  1125. System.out.println();
  1126.  
  1127. System.out.println();
  1128. }
  1129.  
  1130. }
  1131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement