Algorithms and OOD (CSC 207 2013F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Admin
HW 2
For the averaging problem, there are a variety of strategies
Promote the type of the parameters.
double. We'll talk about why that's
a bad idea.
public static long average(long left, long right) { return (left + right) / 2; } // average
public static long average(long left, long right) {
return (long) (((double) left + (double) right) / 2);
} // average
how about this?
public static long average(long left, long right) {
return (left/2) + (right/2);
} // average
nope, won't work if both are odd ... so
public static long average(long left, long right) {
// Compute the average w/o overflow
long tmp = (left/2) + (right/2);
// Handle introduced inaccuracies
if (isOdd(left) && isOdd(right))
return tmp+1;
else
return tmp;
} // average
coming up: generalized average: taking an array of longs as input
HW 3
splitCSV if the input is crappy (e.g., only one
double quotation mark) - You can crash and burn. Can create with files - new PrintWriter(new File('ooh.csv')) ;
BufferedReader
public static void main(String[] args) throws Exception {
// ...
}
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.