-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTravelAgenciesProblem.java
More file actions
87 lines (73 loc) · 2.52 KB
/
TravelAgenciesProblem.java
File metadata and controls
87 lines (73 loc) · 2.52 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
import java.util.*;
class TravelAgencies {
int price;
String packageType;
String agencyName;
int regNo;
boolean flightFacility;
public TravelAgencies(int regNo, String agencyName, String packageType, int price, boolean flightFacility) {
this.regNo = regNo;
this.agencyName = agencyName;
this.flightFacility = flightFacility;
this.price = price;
this.packageType = packageType;
}
public int getRegNo() {
return regNo;
}
public String getAgencyName() {
return agencyName;
}
public String getPackageType() {
return packageType;
}
public boolean getFlightFacility() {
return flightFacility;
}
public int getPrice() {
return price;
}
}
public class TravelAgenciesProblem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TravelAgencies[] arr = new TravelAgencies[4];
for (int i = 0; i < 4; i++) {
int regNo = sc.nextInt(); sc.nextLine();
String agencyName = sc.nextLine();
String packageType = sc.nextLine();
int price = sc.nextInt();
boolean flightFacility = sc.nextBoolean();
sc.nextLine(); // consume newline after boolean
arr[i] = new TravelAgencies(regNo, agencyName, packageType, price, flightFacility);
}
int regNo = sc.nextInt(); sc.nextLine();
String packageType = sc.nextLine();
int maxPrice = findAgencyWithHighestPackagePrice(arr);
System.out.println(maxPrice);
TravelAgencies result = agencyDetailsForGivenIdAndType(arr, regNo, packageType);
if (result != null) {
System.out.println(result.getAgencyName() + ":" + result.getPrice());
}
}
public static int findAgencyWithHighestPackagePrice(TravelAgencies[] arr) {
int max = arr[0].getPrice();
for (int i = 1; i < arr.length; i++) {
if (arr[i].getPrice() > max) {
max = arr[i].getPrice();
}
}
return max;
}
public static TravelAgencies agencyDetailsForGivenIdAndType(TravelAgencies[] arr, int regNo, String packageType) {
for (int i = 0; i < arr.length; i++) {
if (arr[i].getFlightFacility()) {
if (arr[i].getRegNo() == regNo &&
arr[i].getPackageType().equalsIgnoreCase(packageType)) {
return arr[i];
}
}
}
return null;
}
}