Lab instructions

 

Lab1a.java contains a program that will compile and run correctly. 

 

Copy it to your computer and test it. 

 

However, the code is awful.

It doesn’t conform to the guidelines in Appendix F

 

Rewrite the code so that it does conform.

Appendix I contains information about the Javadocs documentation

 

Create a separate Word file in which you document EVERY  code change you make to the program and the  reason for it.

 

Add comments to the program explaining any part of the code that you do not understand when you first read the code.

 

Add comments to the program explaining what the program is doing.

 

 

DELIVERABLES:  PRINTOUT OF YOUR WORD FILE

                           PRINTOUT OF YOUR MODIFIED CODE

 

 

 

see below for version of program to be modified


import java.io.*;

/**

*

* @author - your name

* @version - 1a

*/

public class Lab1a

{

      public static void main(String args [])throws IOException

      {

 

                         BufferedReader stdin = new BufferedReader

                  new InputStreamReader(System.in));

            System.out.println("What is your STARTing number? ");

           

            int START = Integer.parseInt(stdin.readLine());

 

            if (START < 0 || START > 100)

            {

                  System.out.println("Enter a number between 0 and 100");

                  while (START < 0 || START > 100)

                  {

                  START = Integer.parseInt(stdin.readLine());

 

                  if (START >=0 && START <= 100)

                  break;

                  if (START < 0 || START > 100)

                  System.out.println("Enter a number between 0 and 100");

                  }

            }                      

            while (START > 0)

            {

                  System.out.println();

                  if (START == 1)

                        START = lastStanza();

                  if (START == 2)

                        START = almostDone();

                  if (START > 2)

                        START = normalstanza(START);

            }

      }

     

      public static int normalstanza(int Verse)

      {

            System.out.println(Verse + " bottles of pop on the wall");

            System.out.println(Verse + " bottles of pop");

            System.out.println("If one of those bottles should happen to fall");

            System.out.println((Verse - 1) + " bottles of pop on the wall");

 

            return Verse - 1;

      }

     

      public static int almostDone()

      {

            System.out.println("2 bottles of pop on the wall");

            System.out.println("2 bottles of pop");

            System.out.println("If one of those bottles should happen to fall");

            System.out.println("1 bottle of pop on the wall");

 

            return 1;

      }

     

      public static int lastStanza()

      {

            System.out.println("1 bottle of pop on the wall");

            System.out.println("1 bottle of pop");

            System.out.println("If that bottle should happen to fall");

            System.out.println("No bottles of pop on the wall");

 

            return 0;

      }

 

}