280 likes | 377 Views
COP3502: Introduction to CIS I. Lecture 27. Pset 0 3% Pset 1 5% Pset 2 7% Pset 3 15% Pset 4 20% Pset 5 20 % Exam 1 10% Exam 2 10% Labs 10%. l ab 5. c ipher decoder. p roblem set 4. “interactive text adventure”. r eading a file.
E N D
COP3502: Introduction to CIS I Lecture 27
Pset 0 3% • Pset 1 5% • Pset2 7% • Pset 3 15% • Pset 4 20% • Pset 5 20 % • Exam 1 10% • Exam 2 10% • Labs 10%
lab 5 cipher decoder
problem set 4 “interactive text adventure”
reading a file • Open the file • BufferedReaderbr = new BufferedReader(new FileReader(filename)); • Read the file line by line • String line = br.readLine(); • Close the file • br.close();
writing a file • Open the file • PrintWriter pw = new PrintWriter(new FileWriter(filename)); • Print the file line by line • pw.println(text); • Close the file • pw.close();
catching exceptions try { //some code } catch (Exception ex) { //hande the exception in some way }
java collections containers used to store, retrieve, andmanipulate aggregate data generic
java collections containers used to store, retrieve, andmanipulate aggregate data generic ex: arrays
java collections containers used to store, retrieve, andmanipulate aggregate data generic ex: arrays, ArrayList
List interface add() get() remove() size() contains()
Collection List
Collection List ArrayList
Collection List LinkedList ArrayList
Collection Set List Queue HashSet SortedSet LinkedList PriorityQueue NavigableSet ArrayList LinkedHashSet TreeSet
maps set of key/value pairs
examples of maps dictionary phone book
dictionary key: word to look up value: definition access values in a map by looking up the key
dictionary key: word to look up value: definition access values in a map by looking up the key maps Strings to Strings
Map HashMap
Map HashMap SortedMap TreeMap
HashMap new HashMap<K, V>() K – type of key V – type of value
HashMap methods put(key, value)
HashMap methods value = get(key)
HashMap methods remove(key)
HashMap methods contains(key)