wchar_t
and std::wstring
)
while adding
Moroccan_Dirham
, Dollar
… and
Bitcoin
as subclass of Crypto_currency
wchar_t
and std::wstring
)
while adding
Moroccan_Dirham
, Dollar
… and
Bitcoin
as subclass of Crypto_currency
interface Obsolete_currency { // « Currency.java » Currency Default_substitute = new Euro(); default Currency substitute() { return Default_substitute; } default boolean still_active_() { return false; } // C++ time management: https://en.cppreference.com/w/cpp/chrono // or old style with 'std::time_t' in '#include <ctime>'): java.time.LocalDate substitution_date(); } abstract public class Currency { protected final String _common_symbol; // $ <- USA dollar sample protected final int _iso_code; // 840 <- USA dollar sample protected final String _iso_symbol; // USD <- USA dollar sample protected Currency(String common_symbol, int iso_code, String iso_symbol) { _common_symbol = common_symbol; _iso_code = iso_code; _iso_symbol = iso_symbol; } // Resource-based programming: exchange rates have to viewed as external resources on the Web, i.e., // connection to Web services: public double rate(Currency currency) { return 1.D / currency.to_euro_rate(); } abstract public double to_dollar_rate(); public double convert_to_dollar(final double amount) { return amount * to_dollar_rate(); } abstract public double to_euro_rate(); public double convert_to_euro(final double amount) { return amount * to_euro_rate(); } } // End of « Currency.java » public class Euro extends Currency { // « Euro.java » public Euro() { super("€", 978, "EUR"); } public double to_dollar_rate() { return 1.D / 1.03D; // Oct. 17, 2022 exchange rate } public double to_euro_rate() { return 1.D; } } // End of « Euro.java » public class Lats extends Currency implements Obsolete_currency { // « Lats.java » /** Letonia currency replaced by Euro January, 1st 2014 **/ private static final java.time.LocalDate _Substitution_date = java.time.LocalDate.of(2014, java.time.Month.JANUARY, 1); public Lats() { super("Ls", 428, "LVL"); } public double to_dollar_rate() { Currency substitute = substitute(); return rate(this) * substitute.to_dollar_rate(); } public double to_euro_rate() { return 1.D * 0.702804D; // Jan. 1, 2014 exchange rate } public java.time.LocalDate substitution_date() { return _Substitution_date; } } // End of « Lats.java » public class Application { // « Application.java » public static void main(String[] args) { // Obsolete_currency lats = new Obsolete_currency() { // public java.time.LocalDate substitution_date() { // return java.time.LocalDate.of(2014, java.time.Month.JANUARY, 1); // } // }; Euro euro = (Euro) Lats.Default_substitute; Lats lats = new Lats(); System.out.println("100" + euro._common_symbol + " -> " + lats.convert_to_euro(100) + lats._common_symbol); System.out.println("100" + euro._common_symbol + " -> " + euro.convert_to_dollar(100) + "$"); System.out.println("100" + lats._common_symbol + " -> " + lats.convert_to_dollar(100) + "$"); } } // End of « Application.java »
Java