Problem 1
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 output statements! Design your program with a class named BeerSong whose constructor takes an integer parameter that is the number of bottles of beer 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.
Problem 2
Define a class called Counter whose internal "count" variable is a basic integer counter. This class track that count from its instantiation in the constructor (can be set to any positive integer, or 0). The count should never be allowed to be negative. Include methods that will set the counter to 0, increase the count by 1, and decrease the count by 1.
Include an accessor method that returns the current count value (getCount()). There should be no input / setter method or other mutator methods. The only method that can set the counter is the one that sets it to zero (and the constructor).
This class should also override the Object class toString() and equals() methods - refer to the Java APIs for more guidance on how to override this (Chapter 8 also describes this in a little detail, but the API may be more useful): https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html
Finally, write a main method (in this class) to test all the methods in your class definition.
Problem 1: Please see the below code for BeerSong class, screenshots for code and output are attached as well. public class BeerSong { int count; String[] hundredthName = new String[]{"Twenty", "Thirty", "Forty", "Fifty","Sixty","Seventy","Eighty","Ninety"}; String[] unitName = new String[]{"zero","one","two","three","four","five","six","seven","eight","nine","ten", "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"}; public int getCount() { return count; } public void setCount(int count) { this.count = count; } public BeerSong(int count) { if (count<0){ this.count = 0; }else if(count>99){ this.count = 99; }else{ this.count = count; } } public void PrintSong(){ for (int i = count; i >= 0 ; i--) { if(i>=20) { if(i%10==0){ System.out.println(hundredthName[i/10-2]+" bottles of beer on the wall."); }else{ System.out.println(hundredthName[i/10-2]+"-"+unitName[i%10]+" bottles of beer on the wall."); } }else{ System.out.println(unitName[i%10]+" bottles of beer on the wall."); } } } }
Problem 1 Write a program that outputs the lyrics for “Ninety-nine Bottles of Beer on the...
Java hw 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...
Please help me with this Java problem. Would greatly appreciate comments in the code as well: Define a class called Counter whose internal "count" variable is a basic integer counter. This class track that count from its instantiation in the constructor (can be set to any positive integer, or 0). The count should never be allowed to be negative. Include methods that will set the counter to 0, increase the count by 1, and decrease the count by 1. Include...
(Python) 3. 99 Bottles of Beer on the Wall song, recursively Write a function Recurse that prints out the verses of the famous song, Lyrics of the song 99 Bottles of Beer (shown below). You must called this function recursively. 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall. 98 bottles of beer on the wall, 98 bottles of beer. Take one down and...
Java HW Define a class called Counter whose objects count things. An object of this class records a count that is a nonnegative integer. Include methods to set the counter to 0, to increase the count by 1, and to decrease the count by 1. Be sure that no method allows the value of the counter to become negative. Include an accessor method that returns the current count value and a method that outputs the count to the screen. There...
I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly. and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...
code in python I. Problem Statement According to a recent TV commercial, Americans consumed so much bottled water last year that the bottles – if laid end-to-end – would circle the Earth 190 times at the Equator! One can only imagine how disruptive this would be for folks actually living at the Equator! Anyway, approximately how many bottles is that, and what is the average amount of water consumed by each American? Let’s write a program to find out! Better...
C++ program to implement inheritance with following requirements, Classes :- Animal.cpp, bird.cpp, canine.cpp, main.cpp (to test it) :- -You may need getters and setters also. 1. Declare and define an animal base class: animal stores an age (int), a unique long ID (a boolean that is true if it is alive, and a location (a pair of double). animal requires a default constructor and a 3 parameter constructor. Both constructors should set the unique ID automatically. They should also set...
LAB: How many negative numbers Write a program that generates a list of integers, and outputs those integers, and then prints the number of negative elements. Create a method (static void fillArray(int [] array)) that uses Random to generate 50 values (Random.nextInt()), put each value in the array (make sure to pass the array in to this method as an argument). Write another method (static int printAndCountNeg(int [] array)) that prints each element’s value and count the number of negative...
You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...