Computer Science 210
Data Structures

Fall 2016, Siena College

Lecture 03: Java Review: Methods
Date: Monday, September 12, 2016


Agenda

Lecture 03 Assignment

Due at the start of class, Friday, September 16.

Please submit answers to these questions by the start of class. zyBook activities should be done right in your zyBook, and all others should be submitted to Blackboard under "Lecture 03 Assignment" . We will discuss these questions at the start of class, so no late submissions can be accepted.

  1. Write a method that takes an array of double values as its parameter and returns the sum of all elements in the array. (3 points)
  2. What is printed by this program? (8 points)
    private void mystery() {
        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 = increment + report[shot+2];
            }
            if (report[shot] < 10) {
                shot++;
            }
            lastTotal = lastTotal + increment;
            shot++;
            turn++;
            System.out.println(shot + " : " + lastTotal);
        }
    }
    
  3. Write a method that takes an array of String values as its parameter and returns an array of int that contains the lengths of those Strings. That is, each element in the returned array contains the length of the String in the corresponding element of the parameter array. (4 points)
  4. Complete Challenge Activity 8.1.2 in J+DS zyBook. (2 points)
  5. Complete Challenge Activity 8.2.1 in J+DS zyBook. (2 points)
  6. Complete Challenge Activity 8.2.2 in J+DS zyBook. (2 points)
  7. Complete Challenge Activity 8.3.1 in J+DS zyBook. (3 points)
  8. Complete Challenge Activity 8.3.2 in J+DS zyBook. (2 points)
  9. Complete Challenge Activity 8.3.3 in J+DS zyBook. (5 points)
  10. Complete Challenge Activity 8.5.1 in J+DS zyBook. (3 points)
  11. Complete Challenge Activity 8.8.1 in J+DS zyBook. (2 points)
  12. Complete Challenge Activity 8.9.1 in J+DS zyBook. (4 points)
  13. Complete Challenge Activity 8.11.1 in J+DS zyBook. (2 points)
  14. Complete Challenge Activity 8.11.2 in J+DS zyBook. (2 points)

Terminology

Examples