Today, you'll continue with some more word games. You'll also be introduced to Mercurial, a tool for managing the different versions that you make of files. Take a few minutes to read the page about Mercurial; what is there will make more sense as you work through the lab.
For a starting point, clone the repository I have provided. The cloning process will create a new directory, so change into the directory where you want it to be created. Then
$ hg clone /cslab/class/csci235/lab3
That will make a lab3
directory, which will include both
a working copy and a directory. Change into that directory.
The presence of the repository is normally invisible. If you do
ls
, you won't see anything but one Java source file.
However, if you give the -a
(for all) option to
ls
, it will show you the filenames that start with dots.
You should see a couple that start with .hg
.
You can check the status of your working copy with
$ hg status
That won't tell you much right now, because you haven't done
anything. But fire up your editor and make an awful mess of
Palindrome.java
, being sure you save the results.
If you try the status command again, the file will be flagged as
"modified". Now try
$ hg revert Palindrome.javaThat will cause the file
Palindrome.java
to revert to the
last version committed to the repository. You'll need to re-load it
in the editor to see that, but it should look better than your mess.
If you want to use your code from the last lab as a starting point,
you can. Just copy Palindrome.java
from your account to
this directory. (Do you remember how?)
Then, since you want that to be in the repository,
commit it with
$ hg commit -m "Palindrome.java from my lab 2"The message on the end is what you'll be able to see in repository logs.
Your previous program tests whether a string is a palindrome. Now you'll tackle another word game.
A sentence is a pangram if it contains every letter of the alphabet at least once. Examples include
Write a program which prompts the user for a string and determines whether or not that string is a pangram. Ignore spaces, punctuation, and capitalization. Your program should also include an opening documentation block (following the style we've seen in class) and a comment on every variable you declare.
Note: a good way to start would be to copy your palindrome program. You can do that with
$ hg copy Palindrome.java Pangram.java
You use the "hg copy
" command (instead of plain
cp
) so that the repository will know that your new file
is derived from the old one.
If you create a new file (Silly.java
, say) that you want the repository to track, you
use the command
$ hg add Silly.javato tell the repository about it. The contents of the file won't actually go into the repository, though, until you do a commit.
Hint: Think about how you would do this using pencil and paper. You can do this using the methods listed in the textbook, which are also in the simplified online documentation. Need a hint? Another?
Feel free to commit your changes at any time that you have something you might want to go back to. To commit, think of a brief description/label for the state you are about to commit. Then the command
$ hg commit -m "message"with your message substituted.
You can revert the state of a file to its last committed state with
$ hg revert filename
(It is also possible to revert to an earlier committed state, but that is a bit more complicated.)
When you are satsified that you have completed part II, commit with
the message "finished part II
".
Two words or phrases are anagrams of each other if they contain all the same letters (with the same frequency). Examples include
Write a program Anagrams.java
that prompts the user for two
strings.
Test whether the two strings are anagrams of each other.
Ignore spaces, punctuation, and capitalization.
Your program should also include an opening documentation block
(following the style we've seen in class)
and a comment on every variable you declare.
Again, you might want to copy one of your other programs to get a starting point. Don't forget to add your file to the repository and commit (at least) the final version.
Make a script file that shows you compiling your programs and running them with inputs that make it clear that they work correctly. (See how to script.)
Print your two .java
files and the script. (See how to print.)
Use handin
to hand in the files as lab3
, too. (See
how to do that, too.)
There are special ways to copy a directory with a Mercurial
repository. If user msnerd
wants to copy from the lab
account to directory csci235/lab3
under his home
directory, the command would be
$ hg clone . ssh://msnerd@cslab25/csci235/lab3
You'll be prompted for your password, perhaps twice.
When you have logged in to your account and changed into your
csci235/lab3
directory, all that will be there is the
repository. To set up the working copy, you use
$ hg updatewhich makes the working copy match the last committed version from the repository.