



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Portions of this handout by Eric Roberts
Poor naked wretches, wheresoe'er you are, That bide the pelting of this pitiless storm, How shall your houseless heads and unfed sides, Your loop'd and window'd raggedness, defend you From seasons such as these? O, I have ta'en Too little care of this!
MidtermScores.txt 73 58 73 93 82 62 80 53 93 52 92 75 65 95 23 100 75 38 80 77 92 60 98 95 62 87 97 73 78 72 55 58 42 31 78 70 78 74 70 60 72 75 84 87 62 17 92 78 74 65 90
Portions of this handout by Eric Roberts
import acm.program.; import java.io.;
public class WordCount extends ConsoleProgram {
public void run() { int lines = 0; int words = 0; int chars = 0; BufferedReader rd = openFileReader("File: "); try { while (true) { String line = rd.readLine(); if (line == null) break; lines++; words += countWords(line); chars += line.length(); } rd.close(); } catch (IOException ex) { println("An I/O exception has occurred"); } println("Lines = " + lines); println("Words = " + words); println("Chars = " + chars); }
/**
import acm.program.; import acm.util.; import java.io.*;
public class Histogram extends ConsoleProgram {
public void run() { initHistogram(); readScoresIntoHistogram(); printHistogram(); }
/* Initializes the histogram array */ private void initHistogram() { histogramArray = new int[11]; for (int i = 0; i <= 10; i++) { histogramArray[i] = 0; } }
import acm.program.; import java.util.;
public class UniqueNames extends ConsoleProgram {
public void run() { ArrayList
println("Unique name list contains:"); printList(list); }
/* Prints out contents of ArrayList, one element per line */ private void printList(ArrayList list) { for(int i = 0; i < list.size(); i++) { println(list.get(i)); } }
}