File tree Expand file tree Collapse file tree 4 files changed +127
-0
lines changed
currency-convertor/currency-convertor Expand file tree Collapse file tree 4 files changed +127
-0
lines changed Original file line number Diff line number Diff line change
1
+ target /
2
+ ! .mvn /wrapper /maven-wrapper.jar
3
+ ! ** /src /main /** /target /
4
+ ! ** /src /test /** /target /
5
+
6
+ # ## IntelliJ IDEA ###
7
+ .idea /modules.xml
8
+ .idea /jarRepositories.xml
9
+ .idea /compiler.xml
10
+ .idea /libraries /
11
+ * .iws
12
+ * .iml
13
+ * .ipr
14
+
15
+ # ## Eclipse ###
16
+ .apt_generated
17
+ .classpath
18
+ .factorypath
19
+ .project
20
+ .settings
21
+ .springBeans
22
+ .sts4-cache
23
+
24
+ # ## NetBeans ###
25
+ /nbproject /private /
26
+ /nbbuild /
27
+ /dist /
28
+ /nbdist /
29
+ /.nb-gradle /
30
+ build /
31
+ ! ** /src /main /** /build /
32
+ ! ** /src /test /** /build /
33
+
34
+ # ## VS Code ###
35
+ .vscode /
36
+
37
+ # ## Mac OS ###
38
+ .DS_Store
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
+ <modelVersion >4.0.0</modelVersion >
6
+
7
+ <groupId >org.example</groupId >
8
+ <artifactId >CurrencyConverter2</artifactId >
9
+ <version >1.0-SNAPSHOT</version >
10
+
11
+ <dependencies >
12
+ <dependency >
13
+ <groupId >com.squareup.okhttp3</groupId >
14
+ <artifactId >okhttp</artifactId >
15
+ <version >4.10.0</version >
16
+ </dependency >
17
+ <dependency >
18
+ <groupId >org.json</groupId >
19
+ <artifactId >json</artifactId >
20
+ <version >20220924</version >
21
+ </dependency >
22
+ </dependencies >
23
+
24
+ <properties >
25
+ <maven .compiler.source>11</maven .compiler.source>
26
+ <maven .compiler.target>11</maven .compiler.target>
27
+ </properties >
28
+
29
+ </project >
Original file line number Diff line number Diff line change
1
+ package com ;
2
+
3
+ import okhttp3 .OkHttpClient ;
4
+ import okhttp3 .Request ;
5
+ import okhttp3 .Response ;
6
+ import org .json .JSONObject ;
7
+
8
+ import java .io .IOException ;
9
+ import java .math .BigDecimal ;
10
+ import java .util .Scanner ;
11
+
12
+ public class currencyconvertor {
13
+
14
+ public static void main (String [] args ) throws IOException {
15
+
16
+ Scanner scanner = new Scanner (System .in );
17
+ System .out .println ("Type currency to convert from" );
18
+ String convertFrom = scanner .nextLine ();
19
+ System .out .println ("Type currency to convert to" );
20
+ String convertTo = scanner .nextLine ();
21
+ System .out .println ("Type quantity to convert" );
22
+ BigDecimal quantity = scanner .nextBigDecimal ();
23
+
24
+ String urlString = "https://www.frankfurter.app/latest?from=" + convertFrom .toUpperCase ();
25
+
26
+
27
+ OkHttpClient client = new OkHttpClient ();
28
+ Request request = new Request .Builder ()
29
+ .url (urlString )
30
+ .get ()
31
+ .build ();
32
+
33
+ Response response = client .newCall (request ).execute ();
34
+ String stringResponse = response .body ().string ();
35
+ JSONObject jsonObject = new JSONObject (stringResponse );
36
+ JSONObject ratesObject = jsonObject .getJSONObject ("rates" );
37
+ BigDecimal rate = ratesObject .getBigDecimal (convertTo .toUpperCase ());
38
+
39
+ BigDecimal result = rate .multiply (quantity );
40
+ System .out .println (result );
41
+
42
+ }
43
+ }
Original file line number Diff line number Diff line change
1
+ package org .example ;
2
+
3
+ //TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
4
+ // click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
5
+ public class Main {
6
+ public static void main (String [] args ) {
7
+ //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
8
+ // to see how IntelliJ IDEA suggests fixing it.
9
+ System .out .printf ("Hello and welcome!" );
10
+
11
+ for (int i = 1 ; i <= 5 ; i ++) {
12
+ //TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
13
+ // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
14
+ System .out .println ("i = " + i );
15
+ }
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments