From the course: Practical Test-Driven Development for Java Programmers

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Finally writing some code

Finally writing some code

- [Instructor] So we'll have a go then at writing this code. And, because we need to put in some proper logic, I think we'll remove all the code we've got in here and start again. So we'll have a go at writing this code together. I hope you're following along with me. Actually I'm going to make a mistake in here, which we'll discover a little later. I'm doing this on purpose to make a point about how test-driven development works, but I want to say this now because if you spot the mistake, don't worry. I want to pretend that I don't know I've made it. If you haven't spotted the mistake when we get to it, well, that's probably a good thing, because we'll discover it later when we write another test. So the code that we're going to write then is take each of the digits in turn, multiply the first by 10, the second by nine, and so on, add them up, and divide the answer by 11. So, let's start with a variable to store the total, and then we'll need a loop, and we're going to loop for 10…

Contents