Print the lyrics for ninety nine bottles of beer on the wall

Assignment Help JAVA Programming
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();
}}

Reference no: EM13941409

Questions Cloud

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..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd