We need to create methods to make the test compile, watch it fail, then make it pass, step by step. As the textbooks say, we leave this as an exercise to the reader.
I'm not sure if you are looking for any specific comments, but here's what I would say if doing a code review
1) I'm not sure why "CAD" is hard coded in the class. If it is the default, I would make it a constant with a name that explains the purpose.
2) Is it valid to call convertAtRate() multiple times?
2)(...)Should the program remember the different rates of just the last ones?
3) It looks like the methods/fields are in the order you typed them in. There is nothing forcing you to only enter code at the bottom. In particular, it was hard to find the rate field because it was between methods.
4) Not sure what a1 and a2 do. You should consider some more descriptive names.
5) Is the first constructor (the one that takes an int) still valid? If so, what currency is used?
6) I'm not so comfortable with "return (int) (getValue() * rate);". Does it truncate amounts? If I convert $10 with a rate of 9.99, do I lose money?
I like how you used the final keyword.
And the code definitely looks TDD'd.
Why isn't rate a "private static" variable? In other words, why isn't it private?
private double rate; (i dont see the need of making it static)
Originally posted by Jeanne Boyarsky:
2) What should happen if I run the following code?
Logically I would expect it to convert to euros. The current implementation would not longer have the exchange rate though. I guess I'm asking whether the program is meant to only support two currencies at a time? (USD and EUR) In this case CAD is the last currency I was referring to.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton