Loved studying this chapter and the related material. Here are the code for the more trickier exercises at the end of the chapter.
Quadratic Equation:
I’ve explained my strategy in the comments. I would have liked to return both the solutions back to the run method for further manipulation, but I don’t know how to return two variables from a method. (Or if its even possible). I’m sure there is some way to use arrays to achieve that but I haven’t yet touched the topic of arrays so I’ll leave it for later.
askYesNoQuestion
This problem wasn’t that tricky but it needed some thought as it was the first predicate method I wrote. I used the loop-and-a-half trick for this method so that the return statement breaks the while(true) loop.
And the output is something like this:
And 1 more —-
isPrime
I did the brute method myself but had to refer to a math website for the more efficient strategy. Again, everything is explained in the comments.