English subtitles

← Numeric Question - Intro to Java Programming

Get Embed Code
6 Languages

Showing Revision 5 created 09/10/2017 by Dejan Trajkovic.

  1. We just saw that because of Polymorphism, one can write a program that can
  2. handle any mix of quiz questions. Let's try that out and develop another
  3. question type. A numeric question expects an answer from the user that is a
  4. number. For example here we ask what is the area of a circle with radius one.
  5. And the answer is of course pi, but that might be hard to enter, and we can't
  6. really expect the user to type in the exact value of pi, and as you know, this
  7. is not even the exact value, either. It goes on forever. We just want the user
  8. to be able to enter, say, 3.14 or 3.14159, depending on how well they remember
  9. those digits. Either one of those answers should be fine. In fact, we'll take
  10. any answer, that's up to point oh one away, from the answer, that the user
  11. provides. In a different numeric question we might use a different tolerance.
  12. Your task is to implement this new question type. We've given you the
  13. constructor, your job is to provide the set answer method. And the check answer
  14. method. And the check answer method, you need to take the tolerance into
  15. account, you need to check whether the given number is not too far away from
  16. the response. So, technical issue the response is a a string, you need to convert
  17. it to a number. And we show you here how to do that. You may need additional
  18. instance variables. And then you should put them here. Go ahead, give this a
  19. try.