![]() Now how exactly you fit all this in with TDD I'm not quite sure. An alternative form is called "postfix", which is used in Reverse Polish notation, and that is extremely easy for a program to parse.Īnd luckily for you, a very clever chap called Edgar Dijkstra invented a way of translating one to the other called the Shunting Yard algorithm. (Hint: You may find that you have to go through the string more than once)Īnother thing that might be useful to know: The way we write arithmetic is called " infix notation" - and it's not a natural fit for programs. For example, suppose you get the string " 6?8/(2-4*5)", or (more difficult) " 6+8(2-4*5)" - what do you want your program to do? Once you have a set of instructions in English (and not before), then think how to translate them into Java.Īnd when you do that, think about what might go wrong. Is there any knowledge they need before they start? (Hint: what's the result of "2-4*5", and why?).What do they have to do, precisely, and why?.How would you explain to them how to evaluate the string" 6+8/(2-4*5)"? In detail. Imagine you have a reasonably intelligent 10-year old child who doesn't know Java. My first suggestion: Forget TDD, forget SOLID - in fact, forget Java for the moment. I really ave no idea how to go about this. At this point, I'd avoid regular expressions - which basically rules out Matcher and Pattern - and concentrate on going through your String character by character (which will need charAt()). Would you be so kind in to helping me without telling me the answers? ![]() The problem is, I have no idea where to start reading. I started doing searches and learned about a couple libraries with Classes called Matcher and Pattern, I learned of tokenizer, and I also learned of split. I realized really quickly that I do not know what to even look up. What do you want them to return? Particularly the last one. Sounds reasonable however, you then (I presume) might also have "1-2", "1*2" and "1/2". ![]() So I decided to start with "1+2" and want it to return "3". Michael Bruce Allen wrote:I am learning TDD and using SOLID principals to make a calculator that can take a string "6+8/(2-4*5)" and calculate it properly.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |