Take the program from the prior lesson and add some dynamic capability by asking the user for values and using them in the program.
1. Make your program prompt the user for their name. Then make your program use the name as so:
~> Welcome to the PI exponentiator! What is your name?
~> Hello so-and-so, here are your PI values:
~> same output as in prior lesson follows
2. After asking them for their name, also ask them to what power of PI would they like to see. If the value they type is not an integer, or it's greater than 10, make the program re-prompt them, telling them invalid value. E.g.
~> Welcome to the PI exponentiator! What is your name?
~> Chuck
~> Hello Chuck, what power of PI being raised to would you like?
~> none
~> Sorry Chuck, invalid value, please enter the number again.
~> 4
~> print prior lessons output to the 4th power
Goals for this lesson: Process dynamic input values, use conditional logic, basic validation, control flow with if-then constructs, introduction to Exception - in particular NumberFormatException.
Suggested reading: Intro chapters in a java book. Read the section explaining Exception.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment