Tina Comston
Comp-111 Week 8
Franklin University
Week 8
Preparation
    • Read Chapter 6 (sections 6.1 - 6.8) in the COMP 111 Reading Guide.
      Guided Learning Activity
      Assignment
      • Problem 1
      Loops

      There are 3 loop types that are supported in Java.

      while (condition)
      {
          statements to execute
      }

      This is a condition controlled pre-test loop. The condition is first checked and if true, the loop executes.  It continues to execute as long as the condition is true.  This type of loop can always be used, but is most often used when you are unsure of how many times the loop will execute.


      do
      {
           statements to execute
      }
      while(condition)

      This is a condition controlled post-test loop.  The do/while loop executes the statements first and then checks the condition.  This type of loop is used when you need the statements to execute at least once before checking the condition.



      for (int varName=default; condition; increment/decrement)
      {
          statements to execute
      }

      This is a count controlled pre-test loop.  This type of loop first checks the condition and if true executes the statements a set number of times.  It is used when you know how many times the loop should execute.
       



      Regardless of the type of loop the following occurs:

      set the initial value for the condition
      check the condition
           execute the body of the loop
            modify the condition


      In the FOR loop these are all combined into the initial statement

      for (int varName=default; condition; increment/decrement)
      • int varName = default
        • declare the variable and set to an initial value.  Typically the variables i, j, or k are used with this type of loop.  Often the initial value is 0 or 1, but it does not have to be.
      • condition
        • comparing the variable i, j, or k to a condition, perhaps i < 10 or j < 100
      • increment/decrement
        • modifying the variable, perhaps i++, or j+2

      YouTube video on loops https://www.youtube.com/watch?v=0ll7vm1GQYE

        • Copy the code into a BlueJ class.
        • Compile
        • Execute
        • Review the output.
        • Modify the code as specified.
        • Compile
        • Execute
        • Review the output.
      • Problem 2
        • Evaluate the code and determine the syntax errors.
          • Hint - use BlueJ to assist in finding the errors.

      • Problem 3
        • Evaluate the code and determine the logic errors.
          • Hint - use BlueJ to assist in finding the errors.
      • Problem 4
        • A FOR loop is really a simplified version of the while loop.
          • Rewrite the WHILE loop as a FOR loop.
          • Rewrite the FOR loop as a WHILE loop.

      • Problem 5
        • Write the test class, class, and drive for a grade calculator.  In this class the user will enter a series of scores for exams, labs, homework, etc.  The maximum number of points that could be earned will be displayed.  The problem can then calculate the grade that the student has earned.
        Reflection Paper
        • Don't forget to jot down your reflections for this week.
        Lab 3
        •  Although you have a couple of weeks to complete this lab, it's never a good idea to wait until the last minute.  Read through the instructions. Make sure you have a clear understanding of what is needed.