Reference no: EM13941409
Write a program that outputs the lyrics for "Ninety Nine Bottles of Beer on the Wall". Your program should print the number of bottles in English, not as a number.
For example:
Ninety nine bottles of beer on the wall,
Ninety nine bottles of beer,
Take one down, pass it around,
Ninety eight bottles of beer on the wall.
...
One bottle of beer on the wall,
One bottle of beer,
Take one down, pass it around,
Zero bottles of beer on the wall.
Your program should not use ninety nine different output statements!
Design your program with a class named BeerSong whose constructor takes an integer parameter that is the number of bottles of beer that are initially on the wall. If the parameter is less than zero, set the number of bottles to zero. Similarly, if the parameter is greater than 99, set the number of beer bottles to 99. Then make a public method called printSong that outputs all stanzas from the number of bottles of beer down to zero. Add any additional private methods you find helpful.
Use the / and % operators to extract the tens digit and the ones digit from the number to be printed. Note that only values between 0 and 99 (inclusive) will be passed to printNumInEnglish.
You may specifically need to test for certain values, such as 0 and 10 through 19
The constructor that you implement should do appropriate range checking for the number of bottles. Specifically, it should check for values that are less than 0 and greater than 99. (Review the problem description for an explanation.)
/**
* This program outputs the 99 bottles of beer on the wall song.
* A simple loop calls a function that outputs each stanza
* for a particular number of bottles of beer.
* <P>
* We use another function that takes a integer from 0-99 and
* outputs that integer as a word. It uses / and % to extract the
* tens digit and the ones digit so we don't need 100 different
* if-then-else statements.
*/
public class BeerSong {
/**
* Number of bottles that we start out with
*/
private int bottles = 0;
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
// --------------------------------
// --------- END USER CODE --------
// --------------------------------
/**
* Outputs an entire stanza for n bottles.
*/
public void printStanza(int n) {
// output n in English
printNumInEnglish(n);
// account for "one bottle" vs. many "bottles"
if (n == 1) {
System.out.println("bottle of beer on the wall, ");
}
else {
System.out.println("bottles of beer on the wall, ");
}
printNumInEnglish(n);
if (n == 1) {
System.out.println("bottle of beer, ");
}
else {
System.out.println("bottles of beer, ");
}
System.out.println("Take one down, pass it around,");
n--;
printNumInEnglish(n);
if (n == 1) {
System.out.println("bottle of beer on the wall.");
}
else {
System.out.println("bottles of beer on the wall.");
}
System.out.println();
}
public void printSong() {
// Loop from 99 down to 0
for (int num = bottles; num > 0; num--) {
printStanza(num);
}
}
public static void main(String[] args) {
BeerSong bs = new BeerSong(23);
bs.printSong();
}}
Technological components of job
: 'In order to successfully redesign jobs, managers need to consider not only changing the technological components of each job; they need to also ensure that any technological change causes minimal or no disruption to the existing social system in ..
|
The real challenge now is how to build the brand
: The real challenge now is how to build the brand while you're losing share and losing trust from those that are still around your thoughts?
|
Strategic nature of the hr function
: Human Resources Information Systems have contributed to the increasingly strategic nature of the HR function'. Discuss.
|
Estimates that the corn revenue yield
: A farmer must decide whether to add fertilizer when planting corn. He estimates that the corn revenue yield will be about $75 per acre without fertilizer and about $100 per acre using fertilizer. If the cost of fertilizer is $20 per acre, what sho..
|
Print the lyrics for ninety nine bottles of beer on the wall
: Write a program that outputs the lyrics for "Ninety Nine Bottles of Beer on the Wall". Your program should print the number of bottles in English, not as a number.
|
Making an application for a divorce in federal circuit court
: You are making an application for a divorce in the Federal Circuit Court of Australia on behalf of your client Janis Anne Copeland.
|
Document belbin team roles
: You have to select two team roles from document Belbin's Team Roles which i have uploaded below and describe them as following the assessment criteria The assessment criteria for the task comprise: 1.
|
What titles should i cover when discussing
: What titles should I cover when discussing how to improve the environmental efficiency of an aircraft engine? (Large passenger)
|
Merger valuation-what is the value of its tax shields
: Hastings Corporation is interested in acquiring Vandell Corporation. Vandell has 1 million shares outstanding and a target capital structure consisting of 30% debt. Vandell's debt interest rate is 7.8%. What is the value of its tax shields? What is t..
|