Below is some code I have written today to test out some bits I have learnt. It isn't much nor is it spectacular. Please critique and let me know what I could/should have done differently or anything I could do to improve it so far.
package easy8;
import java.util.Scanner;
public class song99bottles {
public static void main(String[] args) {
// Declare a reference variable of type song99bottles - new object
song99bottles go = new song99bottles();
// calls the method "queston" for object "go".
go.question();
}
public void question(){
song99bottles start = new song99bottles();
String answer;
System.out.println("Would you like to hear a nursery rhyme?\nPlease enter yes or no:");
Scanner input = new Scanner(System.in);
answer = input.next();
if(answer.equalsIgnoreCase("yes")){
start.lyrics();
} else{
System.out.println("Bye");
}
}
public void lyrics() {
int peeps = 10;
String intro = "There were ";
String intro2 = " in the bed and the little one said rollover";
String fall = "\nSo they all rolled over and 1 fell out.";
String end = "And the little said 'I'm lonely'.";
while (peeps > 0){
System.out.println( intro + peeps + intro2 + fall);
peeps--;
if (peeps == 1){
System.out.println(end);
return;
}
}
}
}