![]() |
![]() |
|
We can still write, compile, and run Java programs without using an IDE like BlueJ or Eclipse.
programmer's file editor, which happens to be what the lab computers are configured to start if you click on a .java file in a browser).
must be contained inside a file named Foo.java.Foo
directory-listing), to see the list of files in your current directory.
change directory) to change your current-directory into the folder someDir.
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.
^C) to signify the end-of-input, instead of a number+name.
Windows ^C vs Unix ^D:UseOn unix (and mac), use control-D (
^D) to signify end-of-input rather than control-C (for Windows).unverified: On Windows-8, you also need to use control-D?
Scanner timing: Note that like allScanner methods,hasNext can feel slightly counterintuitive since it answers about the next input past or future; if there is no past input queued up, then the function-call willblockuntil some input finally does arrive. This can be mis-interpreted as an infinite loop, if the user doesn't realize the computer is waiting for them to type something.
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
JVM); but the JVM is a program that your computer does run directly. ↩
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |