diff --git a/TravelCostCalculator.java b/TravelCostCalculator.java index 6f89acb..194036b 100644 --- a/TravelCostCalculator.java +++ b/TravelCostCalculator.java @@ -6,68 +6,68 @@ import java.util.Map; public class TravelCostCalculator { - static Map a = new HashMap<>(); - static Map b = new HashMap<>(); - static Map c = new HashMap<>(); + static Map hotel = new HashMap<>(); + static Map currencyExchange = new HashMap<>(); + static Map flight = new HashMap<>(); - static void l1(String file) throws IOException { + static void list1(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])); + String hotelList; + while ((hotelList = reader.readLine()) != null) { + String[] hotelData = hotelList.split(","); + flight.put(hotelData[0].toUpperCase(), Double.parseDouble(hotelData[1])); } } - static void l2(String file) throws IOException { + static void list2(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])); + String currencyExchangeList; + while ((currencyExchangeList = reader.readLine()) != null) { + String[] currencyExchangeData = currencyExchangeList.split(","); + currencyExchange.put(currencyExchangeData[0].toUpperCase(), Double.parseDouble(currencyExchangeData[1])); } } - static void l3(String file) throws IOException { + static void list3(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])); + String flightList; + while ((flightList = reader.readLine()) != null) { + String[] flightData = flightList.split(","); + flight.put(flightData[0].toUpperCase(), Double.parseDouble(flightData[1])); } } public static void main(String[] args) { try { - l1("data/hotel_rates.csv"); - l2("data/exchange_rates.csv"); - l3("data/flight_costs.csv"); + list1("data/hotel_rates.csv"); + list2("data/exchange_rates.csv"); + list3("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); + double flightCost = flight.getOrDefault(destination, 0.0); + double hotelCost = hotel.getOrDefault(destination, 0.0); System.out.print("Enter your stay duration in days: "); - int stay_duration = Integer.parseInt(reader.readLine()); - hotel_cost *= stay_duration; + int stayDuration = Integer.parseInt(reader.readLine()); + hotelCost *= stayDuration; - double total_cost_usd = flight_cost + hotel_cost; + double totalCostUSD = flightCost + hotelCost; - 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); + System.out.printf("Flight cost: USD %.2f\n", flightCost); + System.out.printf("Hotel cost (%d days): USD %.2f\n", stayDuration, hotelCost); + System.out.printf("Total: USD %.2f\n", totalCostUSD); - 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(); + String[] availableCurrencies = currencyExchange.keySet().toArray(new String[0]); + System.out.print("Select your currency for final price estimation(" + String.join(", ", availableCurrencies) + "): "); + String selectedCurrency = reader.readLine(); - double final_price_local_currency = total_cost_usd * b.get(selected_currency); + double final_price_local_currency = totalCostUSD * currencyExchange.get(selectedCurrency); - System.out.printf("Total in %s: %.2f\n", selected_currency, final_price_local_currency); + System.out.printf("Total in %s: %.2f\n", selectedCurrency, final_price_local_currency); } catch (IOException e) { e.printStackTrace(); }