PhoneNumberParser

PhoneNumberParser (Alpha)

PhoneNumberParser (Alpha)

Prerequisite Information

This practice activity should be done on Odin, so make to complete all of the tutorials in the Unix chapter before attempting it and that you followed the steps in that chapter to activate the CSCI 1302 shell profile on your Odin account. This practice activity also assumes that readers have worked through the material in the Exceptions chapter prior to starting the activity.

Step 1: Get and inspect the starter code

Execute the command below to download and extract the files:

sh -c "$(curl -fsSl https://cs1302uga.github.io/cs1302-book/_bundle/cs1302-phone-alpha.sh)"
- downloading cs1302-phone-alpha bundle...
- verifying integrity of downloaded files using sha256sum...
- extracting downloaded archive...
- removing intermediate files...
subdirectory cs1302-phone-alpha successfully created

Change to the cs1302-phone-alpha directory that was created using cd, then look at the files that were bundled as part of the starter code using tree.

cd cs1302-phone-alpha
tree
.
`-- src
    `-- cs1302
        |-- phone
        |   `-- PhoneNumberParser.java
        `-- prog
            `-- Driver.java

5 directories, 2 files
Step 2: Compile the starter code

From this location, compile each .java file under src into bin separately using javac, the Java compiler command. Make sure that you include the appropriate command-line options to adjust the compiler’s destination directory and, if needed, its class path. Also make sure that you compile the files in reverse-dependency order.

Sample Solution (try to figure out the commands yourself first)
javac -d bin src/cs1302/phone/PhoneNumberParser.java
javac -d bin -cp bin src/cs1302/prog/Driver.java

If you entered the commands correctly, then the output of running tree should now look like this:

tree
.
|-- bin
|   `-- cs1302
|       |-- phone
|       |   `-- PhoneNumberParser.class
|       `-- prog
|           `-- Driver.class
`-- src
    `-- cs1302
        |-- phone
        |   `-- PhoneNumberParser.java
        `-- prog
            `-- Driver.java

9 directories, 4 files

Even though the starter code is not fully implemented, it is provided to you in a state that compiles without any compile-time errors or warnings. With that in mind, run the Driver class from this location using the java command. Make sure that you include the appropriate command-line options to adjust the class path so that the compiler knows where to find the Driver class.

Sample Solution (try to figure out the command yourself first)
java -cp bin cs1302.prog.Driver
Step 3: Edit, recompile, and run the code

Open PhoneNumberParser.java and Driver.java for editing using the emacs command. If you are not familiar with Emacs, then be sure to read the chapter titled “The Emacs Text Editor” found elsewhere in this book.

emacs src/cs1302/phone/PhoneNumberParser.java src/cs1302/prog/Driver.java

One method in each .java file has been left unimplemented. Try to finish the code for the program by implementing those methods. As you go, remember to compile and test your work.

The emacs command shown above opens up both files in Emacs, each in their own Emacs buffer. Use C-x o to switch between those buffers, as needed. Saving one buffer does NOT automatically save other buffers. To save your edits, type C-x C-s in each buffer. If you minimize Emacs using C-z, then remember to bring it back using the fg command instead of rerunning the emacs command – rerunning the emacs command in this scenario will cause your files to be open in mutliple instances of Emacs, which may lead to issues if an older version of a file gets saved by accident. When you are done, you can exit Emacs by typing C-x C-c.

Run the program with your changes until you are confident that it works correctly.

Important

Check Style! Make sure that you run the check1302 command on Odin periodically to check for style guide violations.

check1302 src

Important

Encounter Compiler Errors? If you encounter a compiler error when using javac, then: i) inspect the error message emitted by the compiler carefully; ii) edit the file again to attempt to address the issue;; then iii) recompile to if the error has been resolved. If you encounter multiple compile-time errors, then always try to resolve the first one first just in case it has “domino” effect (i.e., fixing it may sometimes fix subsequent errors).

That’s it! You do not need to turn this in; however, you should keep your work around just in case it comes up again in a future activity.