-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrencyConversionApp.java
More file actions
52 lines (44 loc) · 1.58 KB
/
CurrencyConversionApp.java
File metadata and controls
52 lines (44 loc) · 1.58 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
// Base class: CurrencyConverter
class CurrencyConverter {
public double convert(double amount) {
return amount; // Default implementation (can be overridden)
}
}
// Subclass: USDConverter
class USDConverter extends CurrencyConverter {
@Override
public double convert(double amount) {
return amount * 290 ; // Conversion rate for USD to LKR
}
}
// Subclass: GBPConverter
class GBPConverter extends CurrencyConverter {
@Override
public double convert(double amount) {
return amount * 370; // Conversion rate for GBP to LKR
}
}
// Subclass: EURConverter
class EURConverter extends CurrencyConverter {
@Override
public double convert(double amount) {
return amount * 307; // Conversion rate for EUR to LKR
}
}
// Main class
public class CurrencyConversionApp {
public static void main(String[] args) {
// Create objects for each currency converter
CurrencyConverter usdConverter = new USDConverter();
CurrencyConverter gbpConverter = new GBPConverter();
CurrencyConverter eurConverter = new EURConverter();
// Example conversions
double amountUSD = 100; // 100 USD
double amountGBP = 50; // 50 GBP
double amountEUR = 70; // 70 EUR
// Display results
System.out.println("100 USD in LKR: " + usdConverter.convert(amountUSD));
System.out.println("50 GBP in LKR: " + gbpConverter.convert(amountGBP));
System.out.println("70 EUR in LKR: " + eurConverter.convert(amountEUR));
}
}