-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransport.java
More file actions
187 lines (165 loc) · 4.46 KB
/
transport.java
File metadata and controls
187 lines (165 loc) · 4.46 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import java.util.*;
import java.util.Scanner.*;
class details{
private String name;
private String email;
private long number;
public details(String name,long number,String email)
{
this.name=name;
this.email=email;
this.number=number;
}
@Override //for printing name
public String toString(){
return name;
}
}
public class transport
{
static details[][] a=new details[8][21];
static details[][] b=new details[8][21];
static details[][] c=new details[8][21];
static Scanner sc =new Scanner(System.in);
static String p;
static int choice;
public static void main(String args[])
{
while(choice!=4)
{
System.out.println("Welcome to transport service: ");
System.out.println("1.Book a ticket");
System.out.println("2.View price details");
System.out.println("3.Check your booking");
System.out.println("4.Exit");
choice = sc.nextInt();
switch(choice)
{
case 1:View();break;
case 2:Price();break;
case 3:Check();break;
}
}
}
public static void View()
{
Scanner st=new Scanner(System.in);
Scanner sp=new Scanner(System.in);
int flag=0;
System.out.println("Select your day");
System.out.println("1.monday");
System.out.println("2.tuesday");
System.out.println("3.wednesday");
System.out.println("4.thursday");
System.out.println("5.friday");
System.out.println("6.saturday");
System.out.println("7.sunday");
int day = sc.nextInt();
System.out.println("Select your destination");
System.out.println("1.Surat");
System.out.println("2.Banglore");
System.out.println("3.Hyderabad");
int route =sc.nextInt();
if(route==1)
{
for(int seat=1;seat<21;seat++)
{
if(a[day][seat]==null)
{
System.out.println("Seat available");
System.out.println("Price is 1000");
System.out.println("Enter name\n");
String name =st.nextLine();
System.out.println("Enter number");
long num =sc.nextLong();
System.out.println("Enter email");
String id =sp.nextLine();
flag=1;
a[day][seat]=new details(name,num,id);
System.out.println("Booking done Succesfully");
System.out.println("Seat number:"+seat);
break;
}
}
}
if(route==2)
{
for(int seat=1;seat<21;seat++)
{
if(b[day][seat]==null)
{
System.out.println("Seat available");
System.out.println("Price is 2000");
System.out.println("Enter name");
String name =st.nextLine();
System.out.println("Enter number");
long num =sc.nextLong();
System.out.println("Enter email");
String id =sp.nextLine();
flag=1;
b[day][seat]=new details(name,num,id);
System.out.println("Booking done Succesfully");
System.out.println("Seat number:"+seat);
break;
}
}
}
if(route==3)
{
for(int seat=1;seat<21;seat++)
{
if(c[day][seat]==null)
{
System.out.println("Seat available");
System.out.println("Price is 2500");
System.out.println("Enter name");
String name =st.nextLine();
System.out.println("Enter number");
long num =sc.nextLong();
System.out.println("Enter email");
String id =sp.nextLine();
flag=1;
c[day][seat]=new details(name,num,id);
System.out.println("Booking done Succesfully");
System.out.println("Seat number:"+seat);
break;
}
}
}
if(flag==0)
System.out.println("Seats full");
}
public static void Price()
{
System.out.println("Price of tickets:");
System.out.println("Mumbai-Surat Rs1000");
System.out.println("Mumbai-Banglore Rs2000");
System.out.println("Mumbai-Hyderabad Rs2500");
}
public static void Check()
{
System.out.println("Select your day");
System.out.println("1.monday");
System.out.println("2.tuesday");
System.out.println("3.wednesday");
System.out.println("4.thursday");
System.out.println("5.friday");
System.out.println("6.saturday");
System.out.println("7.sunday");
int Day = sc.nextInt();
System.out.println("Select your destination");
System.out.println("1.Surat");
System.out.println("2.Banglore");
System.out.println("3.Hyderabad");
int Route =sc.nextInt();
System.out.println("Enter seat number");
int seatno=sc.nextInt();
System.out.println("This ticket belongs to:");
if(Route==1)
System.out.println(a[Day][seatno]); //prints name
if(Route==2)
System.out.println(b[Day][seatno]);
if(Route==3)
System.out.println(c[Day][seatno]);
}
}