forked from Ritikraja07/Java-problem-Open-Source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrency_Converter.java
137 lines (109 loc) · 4.82 KB
/
Currency_Converter.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//*Task 4 Currency Convertor */
import java.util.*;
import java.text.DecimalFormat;
// Define the main class for the currency converter
public class Currency_Converter {
public static void main(String[] args) {
// Declare variables for different currencies and create a DecimalFormat object for formatting
double rupee, USD, pound, code, euro, KWD, BRS;
DecimalFormat f = new DecimalFormat("##.###");
Scanner sc = new Scanner(System.in); // Create a Scanner object for user input
// Display a menu for currency code selection
System.out.println("\n Enter the currency code \n1:Rupees\n2:US Dollar\n3:Pound\n4:Euro\n5:Kuwati Dinar\n6:Brazilian Real");
code = sc.nextInt(); // Read the selected currency code from user input
// Currency conversion based on the selected code
if(code == 1) {
// Conversion from Rupees to other currencies
System.out.println("Enter amount in rupees:");
rupee = sc.nextFloat();
USD = rupee / 82.9900;
System.out.println("US Dollar :" +f.format(USD));
pound = rupee / 103.68;
System.out.println("Pound :" +f.format(pound));
euro = rupee / 89.14;
System.out.println("Euro :" +f.format(euro));
KWD = rupee / 268.75;
System.out.println("Kuwati Diner :" +f.format(KWD));
BRS = rupee / 16.39;
System.out.println("Brazilian Real :" + f.format(BRS));
}
else if(code == 2) {
// Conversion from US Dollars to other currencies
System.out.println("Enter amount in US Dollar:");
USD = sc.nextFloat();
rupee = USD * 82.97;
System.out.println("Rupees :" +f.format(rupee));
pound = USD * 0.80;
System.out.println("Pound :" +f.format(pound));
euro = USD * 0.93;
System.out.println("Euro :" +f.format(euro));
KWD = USD * 0.31;
System.out.println("Kuwati Diner :" +f.format(KWD));
BRS = USD * 5.07;
System.out.println("Brazilian Real :" + f.format(BRS));
}
else if(code == 3) {
// Conversion from Pounds to other currencies
System.out.println("Enter amount in Pound:");
pound = sc.nextFloat();
rupee = pound * 103.59;
System.out.println("Rupees :" +f.format(rupee));
USD = pound * 1.25;
System.out.println("Pound :" +f.format(pound));
euro = pound * 1.16;
System.out.println("Euro :" +f.format(euro));
KWD = pound * 0.39;
System.out.println("Kuwati Diner :" +f.format(KWD));
BRS = pound * 6.23;
System.out.println("Brazilian Real :" + f.format(BRS));
}
else if(code == 4) {
// Conversion from Euros to other currencies
System.out.println("Enter amount in Euro:");
euro = sc.nextFloat();
rupee = euro * 89.11;
System.out.println("Rupees :" +f.format(rupee));
pound = euro * 0.86;
System.out.println("Pound :" +f.format(pound));
USD = euro * 1.07;
System.out.println("US Dollar :" +f.format(USD));
KWD = euro * 0.33;
System.out.println("Kuwati Diner :" +f.format(KWD));
BRS = euro * 5.37;
System.out.println("Brazilian Real :" + f.format(BRS));
}
else if(code == 5) {
// Conversion from Kuwaiti Dinars to other currencies
System.out.println("Enter amount in Kuwaiti Dinar:");
KWD = sc.nextFloat();
rupee = KWD * 268.80;
System.out.println("Rupees : "+f.format(rupee));
USD = KWD * 3.24;
System.out.println("US Dollar : "+f.format(USD));
pound = KWD * 2.60;
System.out.println("Pound : "+f.format(pound));
euro = KWD * 3.02;
System.out.println("Euro : "+f.format(euro));
BRS = KWD * 16.41;
System.out.println("Brazilian Real:" + f.format(BRS));
}
else if (code == 6){
//Conversion from Brazilian Real to other currencies
System.out.println("Enter amount in Brazilian Real:");
BRS = sc.nextFloat();
rupee = BRS * 16.42;
System.out.println("Rupees : "+f.format(rupee));
USD = BRS * 0.20;
System.out.println("US Dollar : "+f.format(USD));
pound = BRS * 0.16;
System.out.println("Pound :" +f.format(pound));
euro = BRS * 0.19;
System.out.println("Euro : "+f.format(euro));
}
else {
// Invalid currency code input
System.out.println("Invalid Code!");
}
sc.close();
}
}