Java代写|OOP|面向对象编程|命令行程序 Encode Utility — Deliverable 2
Encode Utility — Deliverable 2
Project Goals
- ● Develop a Java application for replacing strings within a file.
-
● Get experience with an agile, test-driven process.
Details
For this project you must develop, using Java, a simple command-line utility called
encode, which is the same utility for which you developed test frames in the
category-partition assignment. For Deliverable 1, you have developed a first
implementation of encode that makes your initial set of test cases pass. For this
second deliverable, you have to modify your implementation to account for a slight
update in the specification for encode requested by your customer. The updated
specification is below, with the changed parts marked in red:
Concise (Updated) Specification of encode utility
● NAME:
encode – encodes words in a file.
● SYNOPSIS
encode OPT <filename>
where OPT can be zero or more of
○ -d <string>
○ -w
○ -x <char>
○ (-r | -k) <string> ○ -c
● COMMAND-LINE ARGUMENTS AND OPTIONS
<filename>: the file on which the encode operation has to be performed.
-d <delimiters>: if specified, the utility will treat the required string argument, delimiters, as the list of delimiter characters used by all other options to separate words, where a word is a sequence of characters terminated by one or more delimiter characters (or the end of the file). If this option is not specified, all whitespace characters are treated as the default delimiters. The delimiter characters in the file will not be changed by – r, -k, or -c options.
-w: if specified, the utility will reverse the characters in each word, where a word is a sequence of characters terminated by any of the current delimiter characters (as specified by -d or the default of whitespace), or the end of the file.
-x <char>: if specified, the utility will replace the current delimiter characters (as specified by -d or the default of whitespace) between each word with the provided character. Contiguous, uninterrupted sequences of delimiter characters are replaced by only one of the provided character. This option is always executed last.
(-r|-k) <string>: if specified, the utility will remove(-r) or keep (-k) only the alphanumeric characters (capitalization insensitive) in the file which are included in the required <string>. All non-alphanumeric characters are unaffected. -r and -k are mutually exclusive.
-c: if specified, the encode utility will reverse the capitalization (i.e., lowercase to uppercase, and uppercase to lowercase) of all alphabetic characters in the file.
If none of the OPT flags is specified, encode will default to applying -w, using all non-alphanumeric characters as delimiters (as if all non-alphanumeric characters were passed to -d).
● NOTES
○ While the last command-line parameter provided is always treated as
the filename, OPT flags can be provided in any order. ● EXAMPLES OF USAGE
Example 1:
encode file1.txt
(where the content of the file is “abc tuvw.XYZ”)
Reverses order of letters in each word in the file. (resulting in “cba wvut.ZYX”).
Example 2:
encode -r aZ file1.txt
Removes all instances of a, A, z and Z from the file.
Example 3:
encode -w -d “:,” -k “aeiouxyz” file1.txt
Reverses the order of characters in each set of characters separated by a colon
or comma. 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 -w -c file1.txt
Reverses the order of characters in each set of characters separated by any form of whitespace. Also reverses the capitalization of all alphabetic characters,
from upper to lower and lower to upper.
Example 5:
encode -d “. ” -x “!” file1.txt
Replaces all groups of one or more spaces and periods with exclamation marks.
Deliverables:
DELIVERABLE 1 (done) DELIVERABLE 2 (this deliverable)
● provided:
- ○ Additional set of JUnit test cases (to replace MainTest.java and be run in addition to yours)
- ○ Updated encode specification ● expected:
○ Implementation of encode that makes all test cases pass
DELIVERABLE 3
- ● provided: TBD
-
● expected: TBD
Deliverable 2: Instructions
1. Download archive individualProject-d2.tar.gz
2. Unpack the archive in the root directory of the personal GitHub repo that we assigned to you. After unpacking, you should see the following files: ○ <root>/IndividualProject/…/encode/MainTest.java ○ <root>/IndividualProject/…/encode/MainTestSuite.java
3. Class MainTest is the originally provided test class with both updated and additional test cases for the encode utility. It should replace your original MainTest.java file. Imagine that these are test cases developed by coworkers who were also working on the project and developed tests for encode based on (1) updated customer requirements and (2) some of the discussion about the semantics of encode that took place on Piazza during the week. As was the case for the test cases we provided for Deliverable 1, all these tests must pass, unmodified, on your implementation of encode.
Please note that these tests clarify encode’s behavior and also make some assumptions on the way encode works. You should use the test cases to refactor your code.
In most cases, we expect that these assumptions will not violate the assumptions you made when developing your test cases for Deliverable 1, but they might in some cases. If they do, please adapt your test cases (and possibly your code) accordingly, which may also give you an additional opportunity to get some experience with refactoring.
To summarize: all the test cases in the new MainTest class should pass (unmodified) and all the test cases in the MyMainTest class should pass (possibly after modifying them) on your implementation of encode.
Please ask privately on Piazza if you have doubts about specific tests. We will make your question public if it is OK to do so.
- Class MainTestSuite is a simple test suite that invokes all the test cases in test classes MainTest and MyMainTest. You can use this class to run all the test cases for encode at once and check that they all pass. This is how we will run all the test cases on your submission.
- Commit and push your code. You should commit, at a minimum, the content of directory <dir>/encode/test and <dir>/encode/src. As usual, committing the whole IntelliJ IDEA project, in case you used this IDE, is fine.
- Paste the commit ID for your submission on Canvas, as usual.
Notes
- ● As usual, this assignment should use Java 11 or 12 and Junit 4.*.
- ● 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). We would encourage adapting the provided utility classes for reading and writing the files. If you do not, be sure to review any limitations of the file reading and writing methods that you use.
● Your tests and the provided tests should be able to run and pass as a suite,
rather than only passing when run individually, so your tests must not
interfere with each other.