-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
79 lines (63 loc) · 2.19 KB
/
Copy pathmain.java
File metadata and controls
79 lines (63 loc) · 2.19 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
abstract class Ticket {
private static int totalBookings = 0;
private final int seatNumber;
private String movieName;
public Ticket(String movieName, int seatNumber) {
this.movieName = movieName;
this.seatNumber = seatNumber;
totalBookings++;
}
public String getMovieName() {
return movieName;
}
public int getSeatNumber() {
return seatNumber;
}
public static int getTotalBookings() {
return totalBookings;
}
public abstract double calculatePrice();
}
class RegularTicket extends Ticket {
public RegularTicket(String movieName, int seatNumber) {
super(movieName, seatNumber);
}
public double calculatePrice() {
return 350.0;
}
}
class PremiumTicket extends Ticket {
private double serviceCharge;
public PremiumTicket(String movieName, int seatNumber, double serviceCharge) {
super(movieName, seatNumber);
this.serviceCharge = serviceCharge;
}
public double calculatePrice() {
return 1250.0 + serviceCharge;
}
}
class StudentTicket extends Ticket {
private double discount;
public StudentTicket(String movieName, int seatNumber, double discount) {
super(movieName, seatNumber);
this.discount = discount;
}
public double calculatePrice() {
return 300.0 - discount;
}
}
public class main {
public static void main(String[] args) {
Ticket t1 = new RegularTicket("SPIRIT", 10);
Ticket t2 = new PremiumTicket("VARANASI", 5, 80);
Ticket t3 = new StudentTicket("ANIMAL", 8, 30);
Ticket t4 = new PremiumTicket("SALAAR 2", 7, 70);
Ticket t5 = new RegularTicket("ANIMAL PARK", 18);
System.out.println(t1.getMovieName() + " Price: " + t1.calculatePrice());
System.out.println(t2.getMovieName() + " Price: " + t2.calculatePrice());
System.out.println(t3.getMovieName() + " Price: " + t3.calculatePrice());
System.out.println(t4.getMovieName() + " Price: " + t4.calculatePrice());
System.out.println(t5.getMovieName() + " Price: " + t5.calculatePrice());
System.out.println("Total Bookings: " + Ticket.getTotalBookings());
}
}