From cfcf0cad46ea8e7c97c87e4db0417896b9f2a381 Mon Sep 17 00:00:00 2001 From: Sahaswari Senanayaka <136144909+Sahaswari@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:09:11 +0000 Subject: [PATCH] EG_2020_4185 --- shop_calculator.py => ShopCalculator.py | 0 TravelCostCalculator.java | 69 ++++++++----------- .../{exchange_rates.csv => ExchangeRates.csv} | 0 data/{flight_costs.csv => FlightCosts.csv} | 0 data/{hotel_rates.csv => HotelRates.csv} | 0 data/{promotions.csv => Promotions.csv} | 0 data/{tax_rates.csv => TaxRates.csv} | 0 7 files changed, 28 insertions(+), 41 deletions(-) rename shop_calculator.py => ShopCalculator.py (100%) rename data/{exchange_rates.csv => ExchangeRates.csv} (100%) rename data/{flight_costs.csv => FlightCosts.csv} (100%) rename data/{hotel_rates.csv => HotelRates.csv} (100%) rename data/{promotions.csv => Promotions.csv} (100%) rename data/{tax_rates.csv => TaxRates.csv} (100%) diff --git a/shop_calculator.py b/ShopCalculator.py similarity index 100% rename from shop_calculator.py rename to ShopCalculator.py diff --git a/TravelCostCalculator.java b/TravelCostCalculator.java index 6f89acb..da810bc 100644 --- a/TravelCostCalculator.java +++ b/TravelCostCalculator.java @@ -1,3 +1,5 @@ +// Samoda S.M.S.T- EG/2020/4185 + import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; @@ -10,66 +12,51 @@ public class TravelCostCalculator { static Map b = new HashMap<>(); static Map 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 { + static void BufferReaderLine2(String file,letter) 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])); + while ((String line = reader.readLine()) != null) { + String[] words = line.split(","); + if(letter=='a') + a.put(words[0].toUpperCase(), Double.parseDouble(words[1])); + else if (letter=='b') + b.put(words[0].toUpperCase(), Double.parseDouble(words[1])); + else if (letter=='b') + c.put(words[0].toUpperCase(), Double.parseDouble(words[1])); } } public static void main(String[] args) { try { - l1("data/hotel_rates.csv"); - l2("data/exchange_rates.csv"); - l3("data/flight_costs.csv"); + BufferReaderLine1("data/hotel_rates.csv",a); + BufferReaderLine2("data/exchange_rates.csv",b); + BufferReaderLine3("data/flight_costs.csv",c); 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 = c.getOrDefault(destination, 0.0); + double hotelCost = 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; + + double totalCostUsd = flightCost + ( hotelCost *= stayDuration); - 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 = b.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 finalPriceLocalCurrency = totalCostUsd * b.get(selectedCurrency); - System.out.printf("Total in %s: %.2f\n", selected_currency, final_price_local_currency); - } catch (IOException e) { - e.printStackTrace(); + System.out.printf("Total in %s: %.2f\n", selectedCurrency, finalPriceLocalCurrency); + } catch (IOException e) { + e.printStackTrace(); } } } diff --git a/data/exchange_rates.csv b/data/ExchangeRates.csv similarity index 100% rename from data/exchange_rates.csv rename to data/ExchangeRates.csv diff --git a/data/flight_costs.csv b/data/FlightCosts.csv similarity index 100% rename from data/flight_costs.csv rename to data/FlightCosts.csv diff --git a/data/hotel_rates.csv b/data/HotelRates.csv similarity index 100% rename from data/hotel_rates.csv rename to data/HotelRates.csv diff --git a/data/promotions.csv b/data/Promotions.csv similarity index 100% rename from data/promotions.csv rename to data/Promotions.csv diff --git a/data/tax_rates.csv b/data/TaxRates.csv similarity index 100% rename from data/tax_rates.csv rename to data/TaxRates.csv