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.
java amateur
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
java amateur
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
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.
java amateur
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Why isn't rate a "private static" variable? In other words, why isn't it private?
java amateur
private double rate; (i dont see the need of making it static)
java amateur
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.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |