diff --git a/currency-convertor/currency-convertor/.gitignore b/currency-convertor/currency-convertor/.gitignore new file mode 100644 index 000000000000..5ff6309b7199 --- /dev/null +++ b/currency-convertor/currency-convertor/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/currency-convertor/currency-convertor/pom.xml b/currency-convertor/currency-convertor/pom.xml new file mode 100644 index 000000000000..ad5c7a3877f0 --- /dev/null +++ b/currency-convertor/currency-convertor/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + org.example + CurrencyConverter2 + 1.0-SNAPSHOT + + + + com.squareup.okhttp3 + okhttp + 4.10.0 + + + org.json + json + 20220924 + + + + + 11 + 11 + + + \ No newline at end of file diff --git a/currency-convertor/currency-convertor/src/main/java/com/currencyconvertor.java b/currency-convertor/currency-convertor/src/main/java/com/currencyconvertor.java new file mode 100644 index 000000000000..d92ed6217a14 --- /dev/null +++ b/currency-convertor/currency-convertor/src/main/java/com/currencyconvertor.java @@ -0,0 +1,43 @@ +package com; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.json.JSONObject; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Scanner; + +public class currencyconvertor { + + public static void main(String[] args) throws IOException { + + Scanner scanner = new Scanner(System.in); + System.out.println("Type currency to convert from"); + String convertFrom = scanner.nextLine(); + System.out.println("Type currency to convert to"); + String convertTo = scanner.nextLine(); + System.out.println("Type quantity to convert"); + BigDecimal quantity = scanner.nextBigDecimal(); + + String urlString = "https://www.frankfurter.app/latest?from=" + convertFrom.toUpperCase(); + + + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(urlString) + .get() + .build(); + + Response response = client.newCall(request).execute(); + String stringResponse = response.body().string(); + JSONObject jsonObject = new JSONObject(stringResponse); + JSONObject ratesObject = jsonObject.getJSONObject("rates"); + BigDecimal rate = ratesObject.getBigDecimal(convertTo.toUpperCase()); + + BigDecimal result = rate.multiply(quantity); + System.out.println(result); + + } +} diff --git a/currency-convertor/currency-convertor/src/main/java/org/example/Main.java b/currency-convertor/currency-convertor/src/main/java/org/example/Main.java new file mode 100644 index 000000000000..a02700ff9885 --- /dev/null +++ b/currency-convertor/currency-convertor/src/main/java/org/example/Main.java @@ -0,0 +1,17 @@ +package org.example; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + System.out.printf("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + System.out.println("i = " + i); + } + } +} \ No newline at end of file