Question: We will be modeling a simple encryption program using a class called CodeGenerator. It will be tested in a class called CodeGeneratorTest, and the program
We will be modeling a simple encryption program using a class called CodeGenerator. It will be tested in a class called CodeGeneratorTest, and the program that uses the CodeGenerator object will be called CodeGeneratorDriver. A CodeGenerator consists of a single data field: an integer offset number. It also has the following methods and constructors: A default constructor that initializes the offset to zero. A setOffset mutator that takes an explicit parameter of the new offset and changes the instance field to match. The offset must be a positive whole number. If a negative number is passed in, the offset should not be changed. A getOffset accessor that will return the value of the offset. A method getCode that takes an explicit parameter of a string representing a character to find the code for and returns the integer code for the letter according to the following rules: o Each letter A through Z is associated with an integer value 0 through 25. o Take the integer for the explicit parameter as determined by the previous line and add the offset to it. o Any numbers beyond 25 should wrap around to the beginning again. o Any character other than A through Z should have a code of -1. For example, if the offset is 20, and the character is Q, then start by finding the integer for Q, namely, 16. Add the offset (20) to 16 to get 36. This is beyond 25, so it wraps around again to 36-26 = 10. Thus, the code for Q with offset 20 is 10. (Consider using the modulus, dividing the character number + offset by 26, to give you the remainder.) In BlueJ, create a class CodeGenerator. Right click on this class and choose Create Test Class, which will create the CodeGeneratorTest class. Finally, create a new class called CodeGeneratorDriver with a main method a. [2 points] Fill in the contents of CodeGeneratorTest with thorough test cases according to the specification above. Paste that code below. Replace this text with your solution. b. [2 points] Fill in the contents of CodeGenerator according to the specification given. Paste that code below. Replace this text with your solution. c. [1 point] Run your test cases and paste a cropped screen shot of your test cases passing their tests when run against CodeGenerator. Replace this text with your solution. d. [1 point] Fill in the contents of CodeGeneratorDriver (the main method) such that: You prompt the user to enter an offset for the code generator. You create a CodeGenerator object and use the first input to set the offset. You prompt the user to enter a character A through Z If the user enters a valid character, display the code; otherwise display an error message. Paste that code below. Replace this text with your solution.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
