lecture18-Objects1

lecture18-Objects1 - Lecture 18: Objects Lecture 18:...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
cture 8: Objects Lecture 18: Objects CS 170, Section 000 November 2009 3 November 2009 11/3/2009 CS170, Section 000, Fall 2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture Plan ± Homework 5 : questions, comments? ¾ Managing Data: objects to make your life easier ¾ ArrayList : (more examples) ashtable ore examples) ¾ Hashtable : (more examples) bj t i J (Ch t 7 t’d) ¾ Objects in Java (Chapter 7 cont’d) CS170, Section 000, Fall 2009 2
Background image of page 2
Homework 5: (due Wed Nov 4 ) Problem: given encrypted text file, break the cipher and print the plain-text (original) message to standard output. http://en.wikipedia.org/wiki/Caesar_cipher Command line arguments: encrypted text, dictionary file (both file names given from command line). Output: original plaintext Simplifying assumptions: No punctuation, numbers in input All words in plaintext are in dictionary, and are in lower case. Dictionary is small (less than 2000 words). 11/3/2009 CS170, Section 000, Fall 2009 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
HW5 (cont’d): Approach Overall approach (brute force/dictionary attack) Assume plain text comes from a dictionary Try all possible shifts until each word in a message is found in e dictionary the dictionary Implementation approach: Read encrypted text from a file, split into words, store into yp , p , array of words (separate string/entry for each word) Read dictionary, store each word (e.g., in array for now), use d ii d lti f h d individual string for each word Write a method to search for a given word from the encrypted text in the dictionary can use Hashtable so store/lookup words in dictionary! 11/3/2009 CS170, Section 000, Fall 2009 4
Background image of page 4
Lecture Plan 9 Homework 5 : questions, comments? ¾ Managing Data: objects to make your life easier ¾ ArrayList : (more examples) ashtable ore examples) ¾ Hashtable : (more examples) bj t i J (Ch t 7 t’d) ¾ Objects in Java (Chapter 7 cont’d) CS170, Section 000, Fall 2009 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What is an ArrayList A dynamically re-sizeable array, so that the total number f elements does not need to be known when created of elements does not need to be known when created ll ocumentation: Full documentation: http://java.sun.com/javase/6/docs/api/java/util/ArrayList.h tml
Background image of page 6
ArrayList, cont'd. ArrayList features think of it as an auto-resizing array, that can hold any type of object, with many convenient methods aintains most of the benefits of arrays such as fast random maintains most of the benefits of arrays, such as fast random access can call toString on an ArrayList to print it remember to import java.util.*; 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ArrayList vs. array import java.util.*; ublic void main(String [] rgs { public void main(String [] args){ //construction String[] names = new String[5]; ArrayList namesList = new ArrayList(); //storage [0 " Ji f " names[0] = "Jennifer"; namesList.add("Jennifer"); //retrieval // String name = names[0]; String name = (String) namesList.get(0); 8 }
Background image of page 8
ArrayList vs. array, cont'd.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 48

lecture18-Objects1 - Lecture 18: Objects Lecture 18:...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online