forked from lasanthasuresh/code_quality_assignment_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTravelCostCalculator.java
75 lines (61 loc) · 2.8 KB
/
TravelCostCalculator.java
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class TravelCostCalculator {
static Map<String, Double> a = new HashMap<>();
static Map<String, Double> b = new HashMap<>();
static Map<String, Double> c = new HashMap<>();
static void l1(String file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
String i;
while ((i = reader.readLine()) != null) {
String[] p = i.split(",");
a.put(p[0].toUpperCase(), Double.parseDouble(p[1]));
}
}
static void l2(String file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
String i;
while ((i = reader.readLine()) != null) {
String[] p = i.split(",");
b.put(p[0].toUpperCase(), Double.parseDouble(p[1]));
}
}
static void l3(String file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
String i;
while ((i = reader.readLine()) != null) {
String[] p = i.split(",");
c.put(p[0].toUpperCase(), Double.parseDouble(p[1]));
}
}
public static void main(String[] args) {
try {
l1("data/hotel_rates.csv");
l2("data/exchange_rates.csv");
l3("data/flight_costs.csv");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your destination: ");
String destination = reader.readLine().toUpperCase();
double flight_cost = c.getOrDefault(destination, 0.0);
double hotel_cost = a.getOrDefault(destination, 0.0);
System.out.print("Enter your stay duration in days: ");
int stay_duration = Integer.parseInt(reader.readLine());
hotel_cost *= stay_duration;
double total_cost_usd = flight_cost + hotel_cost;
System.out.printf("Flight cost: USD %.2f\n", flight_cost);
System.out.printf("Hotel cost (%d days): USD %.2f\n", stay_duration, hotel_cost);
System.out.printf("Total: USD %.2f\n", total_cost_usd);
String[] available_currencies = b.keySet().toArray(new String[0]);
System.out.print("Select your currency for final price estimation(" + String.join(", ", available_currencies) + "): ");
String selected_currency = reader.readLine();
double final_price_local_currency = total_cost_usd * b.get(selected_currency);
System.out.printf("Total in %s: %.2f\n", selected_currency, final_price_local_currency);
} catch (IOException e) {
e.printStackTrace();
}
}
}