-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrencyConverter_task4.java
85 lines (85 loc) · 2.36 KB
/
CurrencyConverter_task4.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
import java.util.Scanner;
class CurrencyConverter_task4
{
static class currency
{
/* currency exchange rates with respect to Indian Rupee
source: Google Finance
date: 11th November 2023 */
double
IND=1,
USD=83.2992,
EUR=89.2592,
JPY=0.5478,
GBP=101.8165,
AUD=52.9866;
String[] name=new String[]{"Indian Rupee","United States Dollar","Euro","Japanese Yen","Pound Sterling","Australian Dollar"};
int n=6;
}
public static void main(String[] args)
{
System.out.println("CURRENCY CONVERTER");
while(true)
{
double r=0;
int i=0,j=0;
currency o=new currency();
Scanner scan=new Scanner(System.in);
for(int k=0;k<o.n;k++)
{
System.out.print("\n"+(k+1)+". "+o.name[k]);
}
System.out.print("\n\nstarting currency: ");
int x=scan.nextInt();
System.out.print("\nending currency: ");
int y=scan.nextInt();
System.out.print("\nenter amount: ");
double amount=scan.nextDouble();
switch(x)
{
case 1:r=o.IND*amount;
i=0;
break;
case 2:r=o.USD*amount;
i=1;
break;
case 3:r=o.EUR*amount;
i=2;
break;
case 4:r=o.JPY*amount;
i=3;
break;
case 5:r=o.GBP*amount;
i=4;
break;
case 6:r=o.AUD*amount;
i=5;
break;
default:System.out.println("INVALID CHOICE");
}
switch(y)
{
case 1:r*=(1/o.IND);
j=0;
break;
case 2:r*=(1/o.USD);
j=1;
break;
case 3:r*=(1/o.EUR);
j=2;
break;
case 4:r*=(1/o.JPY);
j=3;
break;
case 5:r*=(1/o.GBP);
j=4;
break;
case 6:r*=(1/o.AUD);
j=5;
break;
default:System.out.println("INVALID CHOICE");
}
System.out.println("\n"+amount+" "+o.name[i]+" = "+r+" "+o.name[j]);
}
}
}