I'm new to Java and I'm following along with Test Driven Development by Example. In chapter 8 we're exacting subclasses franc and dollar into Money. I've created the factory methods for franc and dollar like so but when I attempt to run the test I get "can not resolve symbol dollar" (or franc) for test lines:
Money five= new Money.dollar(5);
Money four= new Money.franc(5);
I've started over from scratch twice and tried googling it, but I'm not sure what I'm missing.
Money class:
public abstract class Money {
abstract Money times(int multiplier);
protected int amount;
static Money dollar(int amount){
return new Dollar(amount);
}
static Money franc(int amount){
return new Franc(amount);
}
public boolean equals(Object object){
Money money = (Money) object;
return amount == money.amount
&& getClass().equals(money.getClass());
}
}
Franc (Dollar is the same):
public class Franc extends Money {
Franc(int amount){
this.amount = amount;
}
Money times(int multiplier){
return new Franc(amount * multiplier);
}
}
Test:
import org.junit.Test;
import static org.junit.Assert.*;
public class MoneyTest {
@org.junit.Test
public void testMultplication(){
Money five= new Money.dollar(5);
assertEquals(new Dollar(10), five.times(2));
assertEquals(new Dollar(15), five.times(3));
Money four= new Money.franc(5);
assertEquals(new Franc(10), four.times(2));
assertEquals(new Franc(15), four.times(3));
}
}