Lab #4: Project #1 checkpoints and Fun With Scanning In order to do the steps below, you need to have copied over the ~cs61b/hw/proj1 files. In what follows, I assume you are in a directory that contains the Project#1 files, possibly already modified by you. 1. Remove any .class files in your project by issuing a 'gmake clean'. command. Then, in Emacs, use the compile command (C-x C- e or the menu) to execute 'gmake check'. The first thing this command does should be to try to recompile your files (if it doesn't, you've broken something; unbreak it and try this step again). Examine Project #1 Makefile. What is it in this Makefile that causes gmake to recompile your files? Assuming your files compile, 'gmake check' will then try to run the two test cases, which should fail (unless you've already implemented this part of the project!) What do the messages you get mean mean (e.g., the lines that start with "<", or things like "1,2d0"? What Unix command produced those lines? NOTE: I said "In Emacs", and I meant it. If you are NOT using Emacs commands to run all compilations and test scripts, and are instead issuing commands in a shell, you are SEVERELY handicapping yourself in the long run. Emacs, properly used, or (for those of you at home) an IDE (Integrated Development Environment) offering the same compilation-control features prevents errors, keeps your screen uncluttered, and speeds up your interactions considerably. And always remember: I can ask ANYTHING on an exam! 2. How does the Makefile use test-filter? Why do you suppose I included it? It's written in Perl, a language I don't expect you to know. You can run it on a file to see what it does by typing the command perl test-filter NAMEOFFILE in the testing directory (or perl testing/test-filter NAMEOFFILE when in the main project directory). 3. On the basis of the project specification (and any enhancements you may have added in your User-Manual), devise a set of test cases in the style demonstrated by the test*.* files provided for Project #1 and update your Makefile to run them. See if you can systematically test all the required features individually at least. This exercise is something you'll probably want to do outside lab. 4. Use the commands prcs populate prcs checkin in your Project 1 directory to add your test cases to the repository. The steps above do NOT require you to implement any part of the db61b program; your tests ought to work on anyone else's project as well, for example. EXERCISES WITH STRINGS AND SCANNERS The purpose of the following exercises is just to give you a chance to play around with scanning input and using patterns while you have TAs around to help. Be sure to read Chapter 5 of the Blue Reader first, and look over the on-line documentation for java.lang.String, java.util.Scanner, java.util.regex.Pattern, and java.util.regex.MatchResult (that is, scan them to get some idea of what's there). The exercises all have short solutions if you look for and use the right tools. You should create a new file for each exercise, rather than changing one of them. 5. Create a Java source file with a simple main program that reads all the words from the standard input, and prints them, one per line, with all uppercase characters converted to lowercase. Definition: a "word" here is a sequence of non-whitespace characters that is separated from other tokens by whitespace. Definition: for our purposes, "whitespace" consists of blanks, tabs, ends-of-line, and other characters recognized by the Character.isWhitespace method. 6. Modify the program in 5 to print only those tokens that are integer numerals. 7. Modify the program in 5 to print only those tokens that start with a vowel. 8. Run the program in 7 so that it takes this file as its input (that is, make ~cs61b/hw/lab4/ReadMe be the source of the standard input). 9. Now modify the solution to 7 so that when you type just java PROGRAM it behaves as it does now (takes input from the standard input) and when you type java PROGRAM SOMENAME it reads input from a file named SOMENAME instead. 10. Modify the program in 5 to redefine "tokens" to be separated from each other by single commas, semicolons, or newline characters (\n) instead of whitespace (so that the input 'a,,b' produces the THREE tokens "a", "", and "b"). 11. Modify the program in 6 so that it prints any token that CONTAINS exactly one integer numeral somewhere in the middle, printing ONLY that integer numeral (so that for the token 'hi42' or 'one42two', it prints '42', and it doesn't print anything for 'Hello' or '42and43'). 12. Write a program that looks through the standard input, finds the first instance of the phrase: Copyright by . where is a year and is someone's name (it may contain blanks), and prints one line: Author: Assume there will always be such a phrase. Your program should not use any loops or recursion. In fact, once you create a Scanner, you can do this problem in two lines that look like this: theScanner.METHOD1("SOME STRING", 0); System.out.printf ("Author: %s%n", theScanner.METHOD2 ().METHOD3 (SOMETHING)); How do you prevent the program from blowing up if there is no copyright notice?