Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a complete program that uses loops and methods to print the 9 9 Bottles of Beer song. Your song will print the words

Write a complete program that uses loops and methods to print the "99 Bottles of Beer" song. Your song will print the words of the numbers (e.g., Ninety-nine instead of 99).
The Song
"99 Bottles of Beer" is a traditional, repeating sing-along song that counts down from some number to zero. If you are unfamiliar with the song, you can read the lyrics hereLinks to an external site. or watch it being sung hereLinks to an external site..
Part One: Read in the number and validate with a method (10 points)
Your program will allow the user to specify a starting number of bottles. This number can be anywhere between 1 and 99(inclusive). Use a loop to continue asking the user for a number until it is valid, meaning in the specified range.
Write a method that determines if the number if valid. Invoke that method to determine whether you need to keep looping.
For full credit, use constants instead of hard-coded values to make code more readable and easier to maintain.
Part Two: Print the song with words (15 points)
Write a method that prints the song starting at the user's number. Use a loop to print each verse.
Write one or more helper methods that convert a number into the words (e.g.,43 into "Forty-three").
For full credit, you should have no more than 28 hard-coded Strings. All of the numbers between 1 and 99 can be represented with some combination of these 28 Strings:
Ninety, Eighty, ..., Thirty, Twenty (8 strings)
Nineteen, Eighteen, ..., Eleven, Ten (10 strings)
Nine, Eight, ..., One, Zero (10 strings)
Hint: think about how you can use integer division / and modulus % to access a number's tens-place digit and ones-place digit (e.g., for the number 62,6 is the tens-place digit and 2 is the ones-place digit).
Recommendation: Incremental Development
I strongly suggest you work on building up your program a little at a time: code and test, code and test, etc. Here is one possible approach you might use in development.
First, sketch out in words/pseudocode your approach. As part of this, write out what you think the method headers will be: the inputs, outputs, and a descriptive name. Make note of which methods you plan to call from other methods. (See below for the extra credit related to this step!)
Then begin coding. After each step of development, test and revise until that step is fully functional.
Read in and validate a user number using a method
Print out the song using numbers (not words)(e.g.,99 bottles not Ninety-nine bottles)
Convert the numbers to words
Start with the numbers 0-9 only
Then add code for the numbers 10-19
Finally, add code for the numbers 20-99
Note that you do not have to follow this approach. It is just a suggestion. But you should follow some plan of incremental development. Code and test small pieces at a time as you build up your full solution.
General Coding Requirements (10 points)
For full credit, your program should have at least 4 methods (including main). Also:
code should compile
choose the best loops and conditional structures for a task
use constants instead of hard-coded values when possible to improve clarity and readability and to make code easier to maintain
reduce duplicated code (consider how to replace repeated code with a method)
follow Java naming conventions for variables and methods (lower camel case with no underscores)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

Relate the concept of training as an investment.

Answered: 1 week ago