Skip to content

Turning In #72

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 6 commits 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
6 changes: 6 additions & 0 deletions src/main/java/AustralianDollar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class AustralianDollar extends Currency{

public AustralianDollar(double exchangeRate) {
super(exchangeRate, "AU$");
}
}
6 changes: 6 additions & 0 deletions src/main/java/BritishPound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class BritishPound extends Currency{

public BritishPound(double exchangeRate) {
super(exchangeRate, "\u00A3");
}
}
6 changes: 6 additions & 0 deletions src/main/java/CanadianDollar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class CanadianDollar extends Currency{

public CanadianDollar(double exchangeRate) {
super(exchangeRate, "CAN$");
}
}
6 changes: 6 additions & 0 deletions src/main/java/ChineseYuan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class ChineseYuan extends Currency {

public ChineseYuan(double exchangeRate) {
super(exchangeRate, "\u5706");
}
}
57 changes: 57 additions & 0 deletions src/main/java/Currency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
public abstract class Currency {
private double exchangeRate;
private String currencySymbol;


public Currency(double exchangeRate, String currencySymbol){
this.exchangeRate = exchangeRate;
this.currencySymbol = currencySymbol;
}

@Deprecated
public Currency(double exchangeRate){
this(exchangeRate, null);
}

protected void changeRate(double newRate){
this.exchangeRate = newRate;
}

protected double getRate(){
return this.exchangeRate;
}

protected double convertToNewCurrency(double denomination, Currency newCurrency) {
return newCurrency.convertFromDollars(this.convertToDollars(denomination));
}

protected double convertFromDollars(double denominationInDollars) {
double workingDollars = multiplyBy100(denominationInDollars);
return divideBy100(Math.round(workingDollars * this.getRate()));
}

protected double convertToDollars(double denominationInForeignCurrency) {
double workingForeignCurrency = multiplyBy100(denominationInForeignCurrency);
return divideBy100(Math.round(workingForeignCurrency / this.getRate()));
}


protected double multiplyBy100(double valueToMultiply) {
double multipliedValue = Math.round(valueToMultiply * 100);
return multipliedValue;
}

protected double divideBy100(double valueToDivide) {
double dividedValue = valueToDivide / 100;
return dividedValue;
}

protected String displayWithSymbol (double amount){
StringBuilder builder = new StringBuilder();
builder.append(String.format("%4s", this.currencySymbol)).append(" " + amount + "\n");
return builder.toString();
}



}
Empty file removed src/main/java/DELETEME
Empty file.
6 changes: 6 additions & 0 deletions src/main/java/Dollar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Dollar extends Currency {

public Dollar(double exchangeRate) {
super(exchangeRate, "$");
}
}
6 changes: 6 additions & 0 deletions src/main/java/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Euro extends Currency {

public Euro(double exchangeRate) {
super(exchangeRate, "\u20AC");
}
}
6 changes: 6 additions & 0 deletions src/main/java/IndianRupee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class IndianRupee extends Currency{

public IndianRupee(double exchangeRate) {
super(exchangeRate, "\u20A8");
}
}
6 changes: 6 additions & 0 deletions src/main/java/JapaneseYen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class JapaneseYen extends Currency {

public JapaneseYen(double exchangeRate) {
super(exchangeRate, "\u00A5");
}
}
6 changes: 6 additions & 0 deletions src/main/java/MalaysianRinggit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class MalaysianRinggit extends Currency{

public MalaysianRinggit(double exchangeRate) {
super(exchangeRate, "RM");
}
}
6 changes: 6 additions & 0 deletions src/main/java/SingaporeDollar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class SingaporeDollar extends Currency {

public SingaporeDollar(double exchangeRate) {
super(exchangeRate, "S$");
}
}
6 changes: 6 additions & 0 deletions src/main/java/SwissFranc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class SwissFranc extends Currency {

public SwissFranc(double exchangeRate) {
super(exchangeRate, "\u20A3");
}
}
Empty file removed src/test/java/DELETEME
Empty file.
Loading