-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest2Converter.java
More file actions
87 lines (76 loc) · 1.8 KB
/
Test2Converter.java
File metadata and controls
87 lines (76 loc) · 1.8 KB
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
import java.util.Scanner;
// Harrison Holsinger
public class Test2Converter
{
public static void main(String[] args)
{
//Create scanner object
Scanner scan = new Scanner(System.in);
double rate1 = 0.0, rate2 = 0.0, amount = 0.0, subtotal, total;
boolean goodRate1 = false, goodRate2 = false, goodAmount = false;
do
{
System.out.print("Enter a rate of currency to USD(Currency A): ");
try
{
rate1 = Double.parseDouble(scan.next());
goodRate1 = true;
}
catch(IllegalArgumentException e)
{
System.out.println("Invalid argument type entered.");
goodRate1 = false;
}
if(rate1 < 0)
{
goodRate1 = false;
System.out.println("Only Positive Numbers");
}
}
while(goodRate1 == false);
do
{
System.out.print("Enter a different rate of currency to USD(Currency B): ");
try
{
rate2 = Double.parseDouble(scan.next());
goodRate2 = true;
}
catch(IllegalArgumentException e)
{
System.out.println("Invalid argument type entered.");
goodRate2 = false;
}
if(rate2 < 0)
{
goodRate2 = false;
System.out.println("Only Positive Numbers");
}
}
while(goodRate2 == false);
do
{
System.out.print("Enter an amount of currency of Currency A: ");
try
{
amount = Double.parseDouble(scan.next());
goodAmount = true;
}
catch(IllegalArgumentException e)
{
System.out.println("Invalid argument type entered.");
goodAmount = false;
}
if(amount < 0)
{
goodAmount = false;
System.out.println("Only Positive Numbers");
}
}
while(goodAmount == false);
subtotal = amount * rate1;
total = subtotal * (1/rate2);
System.out.printf("The amount of Currency A converted to Currency B is: %.2f", total);
scan.close();
}
}