Skip to content

CurrencyConverter Lab Complete #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface ConvertableCurrency {
default Double convert(CurrencyType currencyType) {
return Double.MAX_VALUE;
return currencyType.getRate() / CurrencyType.getTypeOfCurrency(this).getRate();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.zipcoder.currencyconverterapplication;

public class CurrencyConverter {
public class CurrencyConverter implements ConvertableCurrency{

public static Double convert(Double amountOfBaseCurrency, ConvertableCurrency sourceCurrencyType, CurrencyType targetCurrencyType) {
return sourceCurrencyType.convert(targetCurrencyType) * amountOfBaseCurrency;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.zipcoder.currencyconverterapplication;

public enum CurrencyType {

AUSTRALIAN_DOLLAR(2.70),
CANADIAN_DOLLAR(2.64),
CHINESE_YR(13.84),
Expand All @@ -25,6 +26,14 @@ public Double getRate() {
}

public static CurrencyType getTypeOfCurrency(ConvertableCurrency currency) {

for(CurrencyType currencyType : CurrencyType.values()){
String currencyTypeName = currencyType.name().replace("_", "");
String convertableCurrencyName = currency.getClass().getSimpleName();
if(currencyTypeName.equalsIgnoreCase(convertableCurrencyName)) {
return currencyType;
}
}
return null;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.