Computer Science 252
Problem Solving with Java

Fall 2013, The College of Saint Rose

Lecture 19: Arrays
Date: Tuesday, November 26, 2013


Agenda

Lecture 19 Assignment

Due at the start of class, Tuesday, December 3.

Please submit answers to these questions in Submission Box under "LA19" by the start of our next class. We will discuss these questions at the start of class, so no late submissions are accepted. Please be sure that your name is clearly indicated in all submissions.

  1. What is the output when this method is executed? (8 points)
    private void doSomething() {
    
      int [] report = { 5, 4, 10, 4, 6, 3, 4 };
      int turn = 0;
      int shot = 0;
      int lastTotal = 0;
    
      while (shot < report.length && turn < 10) {
        int increment = report[shot] + report[shot+1];
    
        if (increment >= 10) {
          increment += report[shot+2];
        }
    
        if (report[shot] < 10) {
          shot++;
        }
    
       lastTotal += increment;
       shot++;
       turn++;
    
       System.out.println(shot + " : " + lastTotal);
      }
    }
    
  2. Write a method that takes an ArrayList of Integer values as its parameter and returns the sum of all elements in the array. (4 points)
  3. Write a method that takes an array of double values as its parameter and returns the sum of all elements in the array. (4 points)

Examples