To Notes
CSC 212 -- 1/31/08
Review Questions
Here are the answers.
- Construct a trace table for the
InsertionSort Algorithm
for this array:
42 26 19 35 21 59 40
- Modify the
FindMin.java example so that it finds the
Person
object of minimum age.
- Modify the
InsertionSort.java Example so that it sorts
Person
objects.
Sorting
Reading Data from a File
To read from the file filename.txt in the current directory:
FileReader fr = new FileReader("filename.txt");
Scanner s = new Scanner(System.io);
In addition:
- Import System.util.Scanner and java.io.*.
- Modify the header of the main method:
public static void main(String[ ] argv)
throws FileNotFoundException
Using a relative path name like numbers.txt will not work
with BlueJ. Instead, use an absolute path name like
"c:\\ssmith\\numbers.txt". The character '\\' is the escape sequence for
a single backslash.
See the LoadFromFile Example:
LoadFromFile.java.
Here is the input file:
numbers.txt.
See the FindGender Example
FindGender.java
Person.java.
Here is the input file:
persons.txt.