========================= QUICK DEMO: Random objects > import java.util.Random; > Random x = new Random(); > x.nextInt( 10 ) 3 > x.nextInt( 2 ) 0 > x.nextInt( 2 ) 1 > x.nextInt( 2 ) 0 > x.nextInt( 200 ) 81 > x.nextInt( 200 ) 105 > x.nextInt( 200 ) 149 > x.nextInt( 200 ) 111 > x.nextInt( 200 ) 110 > for (int i = 0; i < 10; i++) System.out.println( x.nextInt( 10 ) ); 9 0 2 9 8 5 7 1 5 3 ========================= OPENING EXERCISE: class to simulate a Die > Die d = new Die(); > d.roll() // several times! ----- discuss parts of the class ----- no instance variables!? ========================= NEXT EXERCISE: supporting different-sided dice > Die d = new Die( 6 ); > d.roll() // several times! > Die duodecimal = new Die( 12 ); > duodecimal.roll() // several times! > Die twenty = new Die( 20 ); > twenty.roll() // several times! ----- discuss new parts of the class +++++ always a "default" constructor > Die hex = new Die( 16 ); > hex.roll() // several times! > Die standardDie = new Die(); > standardDie.roll() // several times! ----- no accessors?? ========================= SLIDES: main() method // Using Tools/Run Document's Main Method > java Die // ***** ALSO BY HAND IN Interactions PANE 10 // ***** ALSO BY HAND AT COMMAND LINE mac os x > cd .../cs1-media/intro-prog-java/bookClasses/ mac os x > java Die 11 ========================= IDEA: using javadoc to generate web doc for classes // look at the Javadoc for Random // via http://java.sun.com/j2se/1.4.2/docs/api/overview-summary.html // ... and generate javadoc for our code mac os x > cd /Users/wallingf/home/teaching/cs1/sessions/session20 mac os x > mkdir javadoc-example/ mac os x > cp DiffSound.java Sound.java javadoc-example/ mac os x > cd javadoc-example/ mac os x > javadoc *.java ----- Sound.java:9: cannot find symbol ----- symbol: class SimpleSound ----- ----- DiffSound.java:9: warning - @date is an unknown tag. mac os x > open index.html ========================= SLIDES: files ----- AFTER HOW TO WRITE A FILE SLIDE > import java.io.*; > BufferedWriter file = new BufferedWriter( new FileWriter("output.txt") ); > file.write( "foo" ); > file.newLine(); > file.write( "bar" ); > file.newLine(); > file.close(); ----- Open output.txt in Finder. ----- (in dir with Dr. Java) ----- Use complete path to specify. ========================= TASK: add a write() method to DiffSound ----- write first sample ----- write # of diffs ----- write each diff ----- Complications: ----- ... I/O exception ----- ... files of characters > Sound s = new Sound( FileChooser.getMediaPath("ew/the-voice-raw.aiff") ); > DiffSound d = s.compress(); > d.write( "ew/the-voice-raw.diff" ); ----- Open the file. See the data. ----- But the file is **bigger** ----- Finish with slides.