Java代写:CS6300 Encode Utility

实现一个Java应用程序,能够对文件进行加密。

encode

Project Goals

  • Develop a Java application for encoding strings within a file.
  • Get experience with an agile, test-driven process.

Details

For this project, you must develop, using the Java language, a simple command-line utility called encode, which is the same utility for which you developed test frames in the category-partition assignment. A concise specification for the encode utility was provided with that assignment and is repeated here for your convenience:

Concise Specification of the encode Utility

  • NAME: encode - encodes words in a file.
  • SYNOPSIS encode OPT filename
    • where OPT can be zero or more of
    • a
    • (-r | -k) [string]
      -c [string]
  • COMMAND-LINE ARGUMENTS AND OPTIONS
    • [filename]: the file on which the encode operation has to be performed.
    • a: if specified, the utility will encode all alphabetic (a-z, A-Z) characters by applying an Atbash Cipher (other characters remain unchanged and the capitalization is preserved), so ‘a’ and ‘A’ would be encoded as ‘z’ and ‘Z’, while ‘y’ and ‘Y’ would be encoded as ‘b’ and ‘B’. This option is always applied last. (-r|-k) [string]: if specified, the utility will remove(-r) or keep (-k) only the alphabetic characters (capitalization insensitive) in the file which are included in the required [string]. All non-alphabetic characters are unaffected. -r and -k are mutually exclusive.
      -c [string]: if specified, the encode utility will reverse the capitalization (i.e., lowercase to uppercase, and uppercase to lowercase) of all the occurrences, in the file, of the characters specified in the required [string] argument.
      If none of the OPT flags is specified, encode will default to applying -c to all letters (A-Z).

NOTES

While the last command-line parameter provided is always treated as the filename, OPT flags can be provided in any order; no matter the order of the parameters, though, option -a will always be applied last.

EXAMPLES OF USAGE

Example 1

encode file1.txt

(where the content of the file is “abcXYZ”)
Reverses the capitalization of all letters. (resulting in “ABCxyz”).

Example 2

encode -r aZ file1.txt

Removes all instances of a, A, z and Z from the file.

Example 3

encode -c "aeiou" -k "aeiouxyz" file1.txt

Changes all occurrences of characters ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ to uppercase, and all occurrences of characters ‘A’, ‘E’, ‘I’, ‘O’ and ‘U’ to lowercase. Then, removes all letters other than ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘x’, ‘y’, ‘z’, ‘A’. ‘E’, ‘I’, ‘O’, ‘U’, ‘X’, ‘Y’ and ‘Z’.

Example 4

encode -a -k abc file1.txt

Removes all letters that are not ‘a’, ‘b’, ‘c’, ‘A’, ‘B’, or ‘C’. Then, encodes ‘a’ to ‘z’, ‘b’ to ‘y’, and ‘c’ to ‘x’ (and the corresponding capitalized equivalents.)

You must develop the encode utility using a test-driven development approach such as the one we saw in P4L4. Specifically, you will perform three activities within this project:

  • For Deliverable 1, you will extend the set of test cases that you created for Assignment 6; that is, you will use your test specifications to prepare 15 additional JUnit tests (i.e., in addition to the 15 you developed for Assignment 6, making for 30 total test cases). Then, you will implement the actual encode utility and make sure that all of the test cases that you developed for Assignment 6 and Deliverable 1, plus the initial test cases provided by us, pass.
  • Deliverables 2 and 3 will be revealed in due time.

Deliverables

DELIVERABLE 1 (this deliverable)

  • provided:
    • Skeleton of main class for encode (Main.java we provided in A6)
    • Initial set of JUnit test cases
      • Tests we provided for A6 (MainTest.java)
      • Tests you created for A6 (MyMainTest.java)
  • expected:
    • 15 additional JUnit test cases
    • Implementation of encode that makes all test cases pass

DELIVERABLE 2

  • provided: TBD
  • expected: TBD

DELIVERABLE 3

  • provided: TBD
  • expected: TBD

Deliverable 1: Instructions

Setup

  1. In the root directory of the personal GitHub repository that we assigned to you, create a directory called “IndividualProject”. Hereafter, we will refer to this directory as [dir].
  2. Copy your MyMainTest.java file from your Assignment6 directory to a corresponding directory in dir.
    This is the test class with your original 15 test cases (to which you will add the additional 15 tests you create for Deliverable 1).
  3. Unpack IndividualProject into [dir]. It includes updated copies of the following files.
    • This is the skeleton of the Main class of the encode utility, which you will have to complete for Deliverable 1 after creating the additional test cases.
    • This provided set of test cases for the encode utility must all pass, unmodified, on the implementation you create. The first test cases correspond to the examples of usage of encode that we provided. The last shows an example of invoking the usage message for an invalid invocation.

Test generation

Generate 15 or more JUnit test cases for the encode utility (in addition to the ones we provided and your original 15 from Assignment 6) and put them in class MyMainTest.

As you did for Assignment 6, you should add a concise comment to each test that states the purpose of the test case and which test frame it implements,using the following format:

1
2
3
// Purpose: [concise description of the purpose of the test]
// Frame #: [test case number in the catpart.txt.tsl of A6]
@Test...

As a reminder, you can reuse and adapt some of the code we provided in the MainTest class (without copying the provided test cases verbatim, of course). But feel also free to implement your test cases differently. We would recommend adapting the provided utility classes for reading and writing the files.

Implementation

Implement the encode utility by completing the Main class, and adding any other class you may need. The requirements for your code are that it passes all the test cases that you created and the ones that we provided, and that it can be executed as follows:

java -cp <classpath> encode.Main <arguments>

Submission

Commit and push your code to your assigned individual repository. You should commit, at a minimum, the content of directories [dir]/encode/test and [dir]/encode/src. As with previous assignments and projects, committing the whole IntelliJ IDEA project, in case you used this IDE, is fine.

Paste the final commit ID for your submission on Canvas, as usual.

Notes

  • After completing your implementation and running your tests, you may find mistakes in the oracles within your tests. You should correct these, even if they are within tests that you created for A6. In other words, your implementation should pass all tests, both new and from A6.
  • If you did not create 15 tests for Assignment 6, you should create additional tests so that you still submit 30 tests overall. For these additional test, you should add a comment in the same format that was requested for A6.
  • If for any reason you cannot create all the required tests using your A6 test frames (e.g., because of errors in the frames or missing frames), create additional tests unrelated to the frames and add to each such test a comment “// not from frame: <reason>“, with a short explanation of why the tests frames cannot be used. Please note, however, that you can and should make tests from your test frames even if they are not ideal (and optionally create additional “not from frame”, better tests). You can contact us privately on Piazza in case of doubts.