RunestoneInteractive / rs

A New Monorepo structure for Runestone
Other
41 stars 68 forks source link

In for loop bottles of pop, need SongTest2 in 2nd version #115

Open kahan002 opened 5 years ago

kahan002 commented 5 years ago

At https://runestone.academy/runestone/static/JavaReview/LoopBasics/lFor.html there is an adapted example with Class SongTest2 to do 3 bottles of pop on the wall... and down. But the call is on Songtest, not Songtest2, so it does not compile. It is not a big deal, because the user can fix it, but I do not believe that was the intent.

kahan002 commented 5 years ago

Also, the output of SongTest2 is:

0 bottles of pop on the wall 0 bottles of pop Take one down and pass it around -1 bottles of pop on the wall

1 bottles of pop on the wall 1 bottles of pop Take one down and pass it around 0 bottles of pop on the wall

2 bottles of pop on the wall 2 bottles of pop Take one down and pass it around 1 bottles of pop on the wall

kahan002 commented 5 years ago

So I think the intent was:

public class SongTest2
{

   public static void printPopSong()
   {
      String line1 = " bottles of pop on the wall";
      String line2 = " bottles of pop";
      String line3 = "Take one down and pass it around";

      for (int i = 0; i < 3; i++)
      {
         System.out.println(3-i + line1);
         System.out.println(3-i + line2);
         System.out.println(line3);
         System.out.println(3-(i + 1) + line1);
         System.out.println();
      }
   }

   public static void main(String[] args)
   {
      SongTest2.printPopSong();
   }
}

which yields

3 bottles of pop on the wall
3 bottles of pop
Take one down and pass it around
2 bottles of pop on the wall

2 bottles of pop on the wall
2 bottles of pop
Take one down and pass it around
1 bottles of pop on the wall

1 bottles of pop on the wall
1 bottles of pop
Take one down and pass it around
0 bottles of pop on the wall