|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
We can still write, compile, and run Java programs without using an IDE like BlueJ or Eclipse.
To compile your program from the command-shell:
If there are errors, the compiler will print them and stop.
If everything works fine, nothing apparent will happen,
but the file Foo.class has been created.
(Use dir to look for it.)
Note that Foo.class contains a version of your program translated into “byte code”, a language that can be understood by the computer directly2.
Enter your favorite number: -3 Enter your favorite beverage: ginger-ale I read the int -3 and the string ginger-ale.
Enter your favorite number: -3 Enter your favorite beverage: ginger-ale In that case, you'll love this verse: -3 bottles of ginger-ale on the wall, -3 bottles of ginger-ale; take one down, pass it around, -4 bottles of ginger-ale on the wall.
Windows ^C vs Unix ^D: On unix (and mac), use control-D (“^D”) to signify end-of-input rather than control-C (for Windows).Use java.util.Scanner#hasNext. See also the example of reading repeated numbers from yesterday's lecture.
Scanner timing: Note that like allScanner methods,hasNext is slightly counterintuitive since it answers about the next input past or future, and needs to stall (“block”) to answer questions about future input.
Enter your favorite number (or ^C to quit): -3 Enter your favorite beverage: ginger-ale In that case, you'll love this verse: -3 bottles of ginger-ale on the wall, … -4 bottles of ginger-ale on the wall. Enter your favorite number: 12345 Enter your favorite beverage: cheerwine In that case, your favorite song must be: 12345 bottles of cheerwine on the wall, … 12344 bottles of cheerwine on the wall. Enter your favorite number (or ^C to quit): ^C Bye!
Write a program which reads in a message, and prints out an encrypted
version of the message (for any of the three low-brow encryption schemes
mentioned below, or one of your own).
In all cases though, use helper functions as appropriate.
(Can you think of useful helper functions you'll write, in advance?)
Please enter your message (^C when done): Four score and seven years ago Frscrndsvnyrsg Our forefath--hmmm, what about our foremothers, were they doing nothing? rfrfth--hmm,whtbtrfrmthrs,wrthydngnthng? ^C bye!Note that although your output is just one long line, it might get printed across several lines because our display is intertwining our output with the user's input3 (which contains newlines).
Please enter your message (^C when done): Four score and seven years ago Sbhe fpber naq frira lrnef ntb Our forefath--hmmm, what about our foremothers, were they doing nothing? Bhe sbersngu--uzzz, jung nobhg bhe sberzbguref, jrer gurl qbvat abguvat? Sbhe fpber! Four score! ^C Bye!
Please enter your message (^C when done): Four score and seven years ago ourFay orescay anday evensay earsay agoay Our forefath--hmmm, what about our foremothers, were they doing nothing? Ouray orefath--hmmm,ay atwhay aboutay ouray oremothers,fay ereway eythay oingday othing?nay ^C Bye!You are of course welcome to handle punctuation better.
Welcome to Encryption Central. Pick your scheme: (1) vowel-removal (2) rot13 (3) pig-latin (0) quit What is your choice? 2 Enter your message (^C to end): Hello there Uryyb gurer ^C Welcome to Encryption Central. Pick your scheme: (1) vowel-removal (2) rot13 (3) pig-latin (0) quit What is your choice? 2 Enter your message (^C to end): Uryyb gurer Hello there ^C Welcome to Encryption Central. Pick your scheme: (1) vowel-removal (2) rot13 (3) pig-latin (0) quit What is your choice? 0 Bye!(Hint: after ^C is typed, you have to create a new
1 You could even use Microsoft Word, if you save-as plain text. Word isn't tailored for Java though, so it won't give you any help with indentation or editing. You'd want to switch to a monospaced font like Courier or Consolas. ↩
2Actually, byte code is interpreted by the Java Virtual Machine (“JVM”); but the JVM is a program that your computer does run directly. ↩
3Technically, the issue is that the terminal automatically echoes all typed input. ↩
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
©2010, Ian Barland, Radford University Last modified 2010.Nov.17 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |