Tina Comston
Comp-111 Exam 2
Franklin University
Exam 2
Exam - to be taken during Week 11
  • Online video review: https://youtu.be/elYW3ODmGfY
  • Proctor
    • I am assuming you will be using the same proctor as for Exam 1.  If this is an incorrect assumption, please let me know ASAP.
  • Preparing for the exam
    • Review the readings for Weeks 6 - 11.
    • Review the Key Points for Modules 6 - 11.
  • Exam Format
    • Paper and Pencil exam, no book, no notes
    • multiple choice questions (3pts each)
    • True/False (2pts each)
    • short answer/coding questions (various point assignments)
  • Exam Topics
    • 4.5: Strings
      4.6: Reading Input
      5.1: The if statement
      5.2: Comparing values
      5.3: Multiple Alternatives
      5.4: Using Boolean Expressions
      5.5T: Code Coverage
      6.1: while loops
      6.2: for loops
      6.4: Processing Sentinel values
      6.5: Random Numbers and Simulations
      7.1: Arrays
      7.2: Array Lists
      7.3: Wrappers and Auto-Boxing
      7.4: The Enhanced for Loop
      7.5: Partially Filled Arrays
      7.8: Two-Dimensional Arrays

  • Exam Practice Questions
  • 4.5 Strings
    • What is the first index position of a string? 
    • In the .substring(int, int) method:
      • What does the first explicit parameter represent?
      • What does the second explicit parameter represent?
      • What element position is the first element position in a string?
    • Using the .substring() method, write the code to do the following for the String variable testString.
      • return just the first character
      • return just the last character
      • remove the first character from the string
      • remove the last character from the string
    • Evaluate the following statements:
      • String quote = “study very hard”;
      • System.out.println(quote.substring(4, 9));
        • Identify the object(s), method(s), parameter(s)
        • Is there an implicit parameter? If yes, what is it?
        • Is there an explicit parameter(s)?  If yes, what is it?
        • What will be the output of these statements?
    • Evaluate the following statement:
      • String output = "Value" + 7/3;
      • What will be the output of this statement?
    • 4.6 Reading Input
      • How is input received from the console?  
        • What object needs to be declared?  
        • How is integer data accepted? 
        • How is double data accepted? 
        • How is string data accepted?
          • What method is used to receive a word?
          • What method is used to receive an entire line?
    • 5.1 - 5.4: If statements, comparing values, boolean expressions
      • What comparison operator is used 
        • To compare 2 integer values?
        • To compare 2 double values?
        • When should you NOT use the == comparison operator?  What should you use instead?
      • Can you use the == comparison operator to compare 2 floating point or double values?
      • What is the purpose of an IF statement?
      • Evaluate the following statement:
        • if ( x == 12 || 8 )
          • Is this a valid statement?  Will it successfully compile?
          • Why or why not?
      • Evaluate the following statement:
        • if (!input.equals("R") || !input.equals("T"))
          • System.out.println("Input is: " + input);
        • What will be printed if input is equal to "R"?
        • What will be printed if input is equal to "T"?
        • What will be printed if input is equal to "Q"?
      • Evaluate the following statement, assuming that quote1 and quote2 are both data type String.
        • quote1.compareTo(quote2)
        • What will be returned if the two String objects are equal?
        • What will be returned if quote1 is alphabetically before quote2?
        • What will be returned if quote2 is alphabetically before quote1?
      • Assuming P is true, Q is false and R is true, what will be the result of:
        • P && Q
        • P || Q
        • !(P && R)
        • !(P || R)
      • Write the code to test gender of an employee printing "Male" if the employee has a gender of M and "Female" if the employee has a gender of F.  Print "Unknown" if neither M or F.  The employee gender can be retrieved through the get method getGender().  The gender value returned is data type char.
      • Write the code to test the age of an employee.  Use the getAge() method to retrieve the age which returns an integer value.  Print the following:
        • If the age is less than 25 print "youngster"
        • If the age is greater than or equal to 25 and less than 35 print "Generation X".
        • If the age is greater than or equal to 35 and less than 45 print "Generation Y".
        • If the age is greater than or equal to 45 print "Baby Boomer".
      • 5.5 Code Coverage
        • How are unit tests in Test Driven Development generally developed?
        • When should they be developed?
      • 6.1 - 6.4: Loops & Sentinel Values
        • What is a sentinel value?
          • Evaluate the following statements:
            • boolean stopLoop = false;
            • int ctr = 0;
            • while (stopLoop)
            • {
            •    if (ctr++ > 12)
            •    {
            •       System.out.println(ctr);
            •       stopLoop = true;
            •    }
            • }
            • How many times will this loop execute?
            • What will be the output from this loop?
          • Describe the four types of loops.  When would each be used?  Know how to write each type of loop.
          • Can a for loop be rewritten as a while loop?  As a do/while loop?
          • What are the four parts of a loop?
          • Write the loop statement to print the value for each element in an array of type String named Dogs.
            • Write the statement using the for loop.
            • Write the statement using the enhanced for loop.
          • Write the code segment to prompt a user for entry of a double value until a sentinel value of -99.99 is entered.  After the sentinel value, compute the average of the numbers entered.
        • 6.5: Random numbers & simulations
          • Evaluate the following code:
            • Random generator = new Random();
            • int newNumber = 5 + generator.nextInt(10);
            • What possible values will the random number generater return based upon the above explicit paramter of 10?
            • What possible values will the integer variable newNumber contain after these statements execute?\
          • Write the statement to generate a random number that represents a roll of a die.  Where each side of the die is represented by the numbers 1 through 6, the 1 is number 1, the 2 is number 2, etc.
        • 7.3: Wrappers & Autoboxing
          • Describe wrapper and autoboxing.  What are the wrapper classes for int, double, boolean, and char?
          • How do you convert a String variable to an integer using the wrapper class?
          • How do you convert a String variable to a double using the wrapper class?
        • 7.1 - 7.8: Arrays & Array Lists
          • Evaluate the following statement, assuming that testArray is defined with a length of 10 and a data type of double.
            • testArray[10] = 104.89;
            • What are the boundaries of the array?
            • Is the double value being inserted within the boundaries?
            • Will this statement compile?  If no, why not?
            • Will an error be produced at run time? if yes, what error?
            • Describe an array verses and ArrayList.  
              • What are the advantages and disadvantages of both?  
              • What type of class is an ArrayList?  
              • What methods are available with an ArrayList?
                • Write the following declaration statements:
                  • Declare an array of 100 Coin objects with a name of tmpCoin.
                  • Declare an array of 50 int values with a name of dogs.
                  • Declare an array of 75 Rat objects with a name of compRats.
                  • Declare a 4 element integer array with a name of scores, and assign the whole numbers 1 through 4 to the array elements.
                  • Declare an ArrayList of data type String and a name of employees.
                  • Declare an ArrayList of Paycheck objects with a name of AnnualPay.
                • How do you return the length of a 
                  • String?
                  • array?
                  • ArrayList?
                • How do you know how many elements within an array have been populated?
                • Write the code to populate an ArrayList with the numbers 0 through 85, where each element is the array list is assigned 1 number.  The first element is assigned 0, the second assigned 1, and so on.
                  • Write the code using a for loop.
                  • Write the code using a while loop.
                  • Write the code using a do/while loop.
                • What is the purpose of the enhanced for loop?
                • Assuming you have an array list of data type string named dogs, write an enhanced for loop to read the entire array list and print out the content of each array element. 
                • Declare a two-dimensional array that has 3 rows and 4 columns of integer values with a name of testScores.
                • Write a loop to populate each element within the array with a value of 0.
              Solution