forked from ossamamehmood/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlightReservationSystem.java
140 lines (92 loc) 路 3.33 KB
/
FlightReservationSystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ossamamehood
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ossamamehmood
*/
public class FlightReservationSystem {
Node root;
// This method adds details of patient to the queue.
// This method adds patient's detail at the end of the queue as per FIFO functionality.
// id stores id of patient.
// @param disease stores disease from which patient is suffering.
void store(int id , String disease) {
Node toAdd = new Node(id , disease);
if(root == null) {
root = toAdd;
return;
}
Node temp = root;
while(temp.next != null) {
temp = temp.next;
}
temp.next = toAdd;
}
// This method deletes the entries of patient from queue.
// It deletes first entry present in queue as per FIFO(First In First Out) functionality.
// @throws Exception if queue is empty, it throws exception.
void delete() throws Exception{
if(root == null) {
throw new Exception("Queue is already empty.");
}
root = root.next;
}
// This method display queue data.
void print() {
if(root == null) {
System.out.println("Can't print an empty queue.");
return;
}
Node temp = root;
while(temp != null) {
System.out.println("Seat number: " + temp.seat + "\tBoarding card: " + temp.card);
temp = temp.next;
}
}
// Node class to store different entries of patients.
class Node{
int seat;
String card;
// next pointer to connect each nodes
Node next;
Node(int seat , String card){
this.seat = seat;
this.card = card;
}
}
// Main method
public static void main(String[] args) throws Exception {
FlightReservationSystem q = new FlightReservationSystem ();
// a) Storing information.
System.out.println("- - - - - - - - - - ");
System.out.println(" Fight Reservation System");
System.out.println("- - - - - - - - - - ");
// Aircarft Seat number Boarding Pass
System.out.println("- - - - - - - - - - ");
System.out.println(" Seat Number || Boarding Pass");
System.out.println("- - - - - - - - - - ");
q.store(66, "AA5920");
q.store(69, "AE6920");
q.store(99, "AF4360");
q.store(69, "BE3350");
// c) Display Flight Record from queue - Here, we're displaying the data fro the Queue
q.print();
// b) Deleting One Record from Queue.
q.delete();
// Displaying the data after deleccting two node from the queue
System.out.println("\nAfter deleting few entries from queue.\n");
q.print();
}
}