-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackathon1.java
More file actions
99 lines (84 loc) · 2.72 KB
/
Hackathon1.java
File metadata and controls
99 lines (84 loc) · 2.72 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
import java.lang.reflect.Array;
import java.util.*;
public class Hackathon1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Theatre[] arr = new Theatre[4];
for (int i = 0; i < arr.length; i++) {
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
int c = sc.nextInt();
double d = sc.nextDouble();
int e = sc.nextInt();
arr[i] = new Theatre(a, b, c, d, e);
}
int value = sc.nextInt();
String ans = findTheatreCategory(arr, value);
if (ans != null) {
System.out.println(ans);
} else {
System.out.println("There is no theatre with the given theatreId");
}
Theatre ans2 = findSecondHighestTicket(arr);
if(ans!=null){
System.out.println(ans2.getThreatreName());
}else{
System.out.println("Only low rating theatres are available");
}
}
public static String findTheatreCategory(Theatre[] arr, int value) {
for (int i = 0; i < arr.length; i++) {
if (value == arr[i].getThreatreId()) {
if ((arr[i].getSeatCapacity() > 1000) && (arr[i].getThreatreRating() >= 4)) {
return "Premium";
} else {
return "Non Premium";
}
}
}
return null;
}
public static Theatre findSecondHighestTicket(Theatre[] arr) {
ArrayList<Theatre> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++) {
if (arr[i].getThreatreRating() >= 2) {
list.add(arr[i]);
}
}
list.sort((a, b) -> Double.compare(b.getTicketRate(), a.getTicketRate()));
if (list.size() < 2) {
return null;
}
return list.get(1);
}
}
class Theatre {
private int threatreId;
private String threatreName;
private int seatCapacity;
private double ticketRate;
private int threatreRating;
public Theatre(int threatreId, String threatreName, int seatCapacity, double ticketRate, int threatreRating) {
this.threatreId = threatreId;
this.threatreName = threatreName;
this.seatCapacity = seatCapacity;
this.ticketRate = ticketRate;
this.threatreRating = threatreRating;
}
public int getThreatreId() {
return threatreId;
}
public String getThreatreName() {
return threatreName;
}
public int getSeatCapacity() {
return seatCapacity;
}
public double getTicketRate() {
return ticketRate;
}
public int getThreatreRating() {
return threatreRating;
}
}