-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicket.java
More file actions
192 lines (170 loc) · 7.29 KB
/
Ticket.java
File metadata and controls
192 lines (170 loc) · 7.29 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
188
189
190
191
192
import java.util.Scanner;
public class Ticket{
int [] seats;
public double finalPrice;
private double price;
private int seatNumber;
Ticket(double price,int seatNumber){
this.price=price;
this.seatNumber=seatNumber;
}
public void calculateFinalPrice(double price,int seatNumber){
}
}
class BusTicket extends Ticket{
private int totalSeats;
private int[] seats;
BusTicket(double price,int seatNumber,int totalSeats,int[] seats){
super(price, seatNumber);
this.totalSeats=totalSeats;
this.seats=seats;
}
public void calculateFinalPrice(double price,int seatNumber,int totalSeats,int[] seats){
double sum=0;
double total;
sum=(price*totalSeats);
total=sum;
if(sum>500) {
double discAmount=sum*10/100;
total=sum-discAmount;
System.out.println("The User Booked Transport: Bus Transport Services!");
System.out.println("Price of One Ticket:"+price);
System.out.println("Seats Booked:");
for (int i = 0; i < (totalSeats-1); i++) {
System.err.print(" "+seats[i]);
}
System.err.println("Total Seats:"+totalSeats);
System.err.println("Total Price to Pay:"+sum);
System.err.println("Discount Applied 10%:"+discAmount);
System.err.println("Final Price to Pay: "+total);
System.err.println("Thankyou for Using Our Services!!");
}else {
System.out.println("The User Booked Transport: Bus Transport Services!");
System.out.println("Price of One Ticket:"+price);
System.out.println("Seats Booked:");
for (int i = 0; i < (totalSeats-1); i++) {
System.err.print(" "+seats[i]);
}
System.err.println("Total Seats:"+totalSeats);
System.err.println("Total Price to Pay: "+total);
System.err.println("Thankyou for Using Our Services!!");
}
}
}
class FlightTicket extends Ticket{
private final int totalSeats;
private final int[] seats;
FlightTicket(double price,int seatNumber,int totalSeats,int[] seats){
super(price, seatNumber);
this.totalSeats=totalSeats;
this.seats=seats;
}
public void calculateFinalPrice(double price,int seatNumber,int totalSeats,int[] seats){
double sum;
double total;
sum=(price*totalSeats);
total=sum;
if(sum>700) {
double discAmount=sum*15/100;
total=sum-discAmount;
System.out.println("The User Booked Transport: Flight Transport Services!");
System.out.println("Price of One Ticket:"+price);
System.out.println("Seats Booked:");
for (int i = 0; i < (totalSeats-1); i++) {
System.err.print(" "+seats[i]);
}
System.err.println("Total Seats:"+totalSeats);
System.err.println("Total Price to Pay:"+sum);
System.err.println("Discount Applied 15%:"+discAmount);
System.err.println("Final Price to Pay: "+total);
System.err.println("Thankyou for Using Our Services!!");
}else {
System.out.println("The User Booked Transport: Flight Transport Services!");
System.out.println("Price of One Ticket:"+price);
System.out.println("Seats Booked:");
for (int i = 0; i < (totalSeats-1); i++) {
System.err.print(" "+seats[i]);
}
System.err.println("Total Seats:"+totalSeats);
System.err.println("Total Price to Pay: "+total);
System.err.println("Thankyou for Using Our Services!!");
}
}
}
class TicketBooking {
public static void main(String[] args) {
int[] seats=new int[30];
try (Scanner sc = new Scanner(System.in)) {
System.err.println("Choose Your Transport!!");
System.err.println("1.Bus Service-Price:100 ");
System.err.println("2.Fligth Service-Price:200 ");
int ch=sc.nextInt();
switch (ch) {
case 1 -> {
double price=100;
int seatNumber;
int total=0;
System.err.println("Total Seats to book");
int totalSeats=sc.nextInt();
boolean check=false;
for(int i=0;i<=(totalSeats-1);i++){
System.err.println("Enter Seat Number:");
System.err.println("Total Seats till 30 only!!");
System.err.println("Give Seat Number less than 30 or equal to 30!!");
seatNumber=sc.nextInt();
if (seatNumber==0 || seatNumber>30){
System.err.println("Wrong Seat-Number Given (Greater than 30)::");
check=true;break;
}
else{
seats[i]=seatNumber;
total++;
}
}
if (check!=true){
System.err.println("First Seat Booked by User:");
seatNumber=seats[0];
BusTicket bs=new BusTicket(price, seatNumber, total,seats);
bs.calculateFinalPrice(price, seatNumber, total,seats);
}
else{
System.err.println("Try Again Later!!");break;
}
}
case 2 -> {
System.err.println("Total Seats to book");
int totalSeats1=sc.nextInt();
double price1=200;
int total = 0;
int seatNumber;
boolean check=false;
for(int i=0;i<=(totalSeats1-1);i++){
System.err.println("Enter Seat Number:");
System.err.println("Total Seats till 30 only!!");
System.err.println("Give Seat Number less than 30 or equal to 30!!");
seatNumber=sc.nextInt();if (seatNumber==0 || seatNumber>30){
System.err.println("Wrong Seat-Number Given (Greater than 30)::");
check=true;break;
}
else{
seats[i]=seatNumber;
total++;
}
}
if (check!=true){
System.err.println("First Seat Booked by User:");
seatNumber = seats[0];
FlightTicket ft=new FlightTicket(price1, seatNumber, total,seats);
ft.calculateFinalPrice(price1, seatNumber,total,seats);
}
else{
System.err.println("Try Again Later!!");break;
}
}
default -> {
System.out.println("Wrong Choice For service !! exiting...");
}
}
}
}
}