Problem: Feed Nibble Monster Till Full Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero. Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e. if the user feeds 'A' hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy). Use while loop. Sample runs: Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full: wer on DESKTOP ZIONDUL MINGWOT / C/ COUT SES/CSZU11/ Code $ java NibbleMonsterwithLoopTill Full Monster hungry :E HUNGER: 2 Feed monster nibble :o a yum! Monster full :). You may go. weron@DESKTOP-2T8KDUL MINGW64 /c/courses/cs2011/code Notice hunger increasing after non-nibble (pink highlight): Weron DESKTOP 21IONDOL MINOWOT / C/ COUT SES/CSZUII/ CODE INOWOT $ java NibbleMonsterwith LoopTill Full Monster hungry :E HUNGER: 384 Feed monster nibble :o b yum! HUNGER: 286 Feed monster nibble :0 EWANI

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Problem: Feed Nibble Monster Till Full

Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero.

 

Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e. if the user feeds 'A' hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy).

 

Use while loop.

 

Sample runs:

Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full:

Notice hunger increasing after non-nibble (pink highlight):

Notice that the program just keeps going when the user feeds the monster only non-nibbles. Do you think the program will keep running forever if the user never gives the monster nibbles?

**Problem: Feed Nibble Monster Till Full**

Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero.

Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e., if the user feeds 'A', hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy).

Use a while loop.

**Sample runs:**

Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full:

```
$ java NibbleMonsterWithLoopTillFull
Monster hungry : E
H U N G E R: 2
Feed monster nibble : o
yum!
Monster full :).
You may go.
```

Notice hunger increasing after non-nibble (pink highlight):

```
$ java NibbleMonsterWithLoopTillFull
Monster hungry : E
H U N G E R: 384
Feed monster nibble : o
yum!
H U N G E R: 273
Feed monster nibble : z
Eww!  o-O
H U N G E R: 395
Feed monster nibble : f
yum!
H U N G E R: 293
Feed monster nibble : o
yum!
H U N G E R: 192
Feed monster nibble : o
yum!
H U N G E R: 136
Feed monster nibble : o
yum!
H U N G E R: 70
Feed monster nibble : o
yum!
Monster full :).
You may go.
```

Notice that the program just keeps going when the user feeds the monster only non-nibbles. Do you think the program will keep running forever if the user never gives the monster nibbles?

```
$ java NibbleMonsterWithLoopTillFull
Monster hungry : E
H U N G E R: 89
Feed monster nibble : o
Eww!  o-O
H U N G E R: 131
Feed monster nibble : o
Eww!  o-O
H U N G E R: 169
Feed monster nibble : o
E
Transcribed Image Text:**Problem: Feed Nibble Monster Till Full** Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero. Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e., if the user feeds 'A', hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy). Use a while loop. **Sample runs:** Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full: ``` $ java NibbleMonsterWithLoopTillFull Monster hungry : E H U N G E R: 2 Feed monster nibble : o yum! Monster full :). You may go. ``` Notice hunger increasing after non-nibble (pink highlight): ``` $ java NibbleMonsterWithLoopTillFull Monster hungry : E H U N G E R: 384 Feed monster nibble : o yum! H U N G E R: 273 Feed monster nibble : z Eww! o-O H U N G E R: 395 Feed monster nibble : f yum! H U N G E R: 293 Feed monster nibble : o yum! H U N G E R: 192 Feed monster nibble : o yum! H U N G E R: 136 Feed monster nibble : o yum! H U N G E R: 70 Feed monster nibble : o yum! Monster full :). You may go. ``` Notice that the program just keeps going when the user feeds the monster only non-nibbles. Do you think the program will keep running forever if the user never gives the monster nibbles? ``` $ java NibbleMonsterWithLoopTillFull Monster hungry : E H U N G E R: 89 Feed monster nibble : o Eww! o-O H U N G E R: 131 Feed monster nibble : o Eww! o-O H U N G E R: 169 Feed monster nibble : o E
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education