Computer Science 210
Data Structures
Fall 2016, Siena College
Lecture 03: Java Review: Methods
Date: Monday, September 12, 2016
Agenda
- Announcements
- if you have not already stopped by my office to get your 3
points for the Lecture 01 assignment, please do so in the next
couple days
- Lab 1: Java Review continues, due tomorrow night
- Lecture 02 assignment recap
- Methods
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.
- 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)
- 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);
}
}
- 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)
- Complete Challenge Activity 8.1.2 in J+DS zyBook.
(2 points)
- Complete Challenge Activity 8.2.1 in J+DS zyBook.
(2 points)
- Complete Challenge Activity 8.2.2 in J+DS zyBook.
(2 points)
- Complete Challenge Activity 8.3.1 in J+DS zyBook.
(3 points)
- Complete Challenge Activity 8.3.2 in J+DS zyBook.
(2 points)
- Complete Challenge Activity 8.3.3 in J+DS zyBook.
(5 points)
- Complete Challenge Activity 8.5.1 in J+DS zyBook.
(3 points)
- Complete Challenge Activity 8.8.1 in J+DS zyBook.
(2 points)
- Complete Challenge Activity 8.9.1 in J+DS zyBook.
(4 points)
- Complete Challenge Activity 8.11.1 in J+DS zyBook.
(2 points)
- Complete Challenge Activity 8.11.2 in J+DS zyBook.
(2 points)
Terminology
- methods (a.k.a. function, procedures, subroutines, subprograms)
- method header
- method body
- method call
- parameters (a.k.a. arguments)
- formal parameter
- actual parameter
- return type
- return value
Examples