Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
/home/rebelsky/share/CSC207.xml
import statement.import java.io.PrintWriter
Introduces a shorthand. You can now refer to
PrintWriterand the Java compiler knows that you meanjava.io.PrintWriter. (It's not clear thatimportdoes much more of use.)
import java.io.*
A shorthand for importing everything from a package. Sam discourages the use, because it makes it harder to figure out what classes come from where.
Many of you had a variable for each line that you read. That seems inefficient.
line1 = fileEyes.readLine(); line2 = fileEyes.readLine(); filePen.println(line1); filePen.println(line2);
Note that copying lines should really be a loop.
private static final int NUMLINES = 2; ... for (int i = 0; i < NUMLINES; i++) { filePen.println(fileEyes.readLine()); } // for
Can you explain the last test?
assertArrayEquals (new String[] { "a", "b", "c" },
StringUtils.splitCSV("a,b,c"));
assertArrayEquals (new String[] { "a,b", "c" },
StringUtils.splitCSV("\"a,b\",c"));
assertArrayEquals (new String[] { "a", "b,b\"", "c" },
StringUtils.splitCSV("a,\"b,b\"\"\",c"));
Sure. We start with the "conceptual units": We want to write a CSV line that represents the three values [a], [b,b"], and [c]. (The square brackets are there to clarify what the units are, they are not part of the units.)
As we try to represent this in CSV, we realize that the middle entity has a comma, so we need to put quotation marks around it.
"b,b"". But there's an internal quotation mark, so we need to double it."b,b""".Our CSV line is now
a,"b,b""",c.We want to represent that as a C/Java string. In C and Java, strings start and end with double-quotation marks and any internal double-quotation marks must be preceded by backslashes. Hence, we get
"a,\"b,b\"\"\",c".Wasn't that fun? Learning to read C strings takes a bit of effort.
How much detail should we put in end braces?
Enough that you can tell what you are ending. For
ifstatements, I tend to prefer that you indicate something about the test, so that you can tell which brace ends which part of a nested if.
} // if (x != 0)
} // if x is valid
Similarly, for a for loop, it's helpful if you indicate which loop variable you are using
} // for (j)
} // for (i)
Should we do unit tests for "The Name Game"?
Probably not. An experiment sufficies.
Start the lab on Exceptions. We'll continue it on Friday.
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (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-14 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.