Assignment 3: Code testing, parameters, return statements Solution

$29.99 $18.99

How to hand in your work Submit the requested file (Encode.java) through the Assignment #3 link on the CSC 110 connex site. Learning outcomes When you have completed this assignment, you should understand: How to write tests to ensure that code runs as intended. How to write and call a static method that receives parameters.…

You’ll get a: . zip file solution

 

 

Description

Rate this product

How to hand in your work

Submit the requested file (Encode.java) through the Assignment #3 link on the CSC 110 connex site.

Learning outcomes

When you have completed this assignment, you should understand:

  • How to write tests to ensure that code runs as intended.

  • How to write and call a static method that receives parameters.

  • How to return a value from a static method.

  • How to use String methods.

  • How to indent and document a Java program.

Download and update the Java program named Encode.java. The program includes a method named encrypt that accepts a String and an int as parameters. The method will return a new encoded String by adding the integer value to each character’s ASCII value, as shown in the examples and following algorithm below.

Examples:

1) String: HELLO key: 2 2) String: TEST key: 11

In your program, you will fill in the code for 3 methods

  1. A static method called testing(), which does the following:

    1. Creates a String to be used as the message to be encoded.

    2. Creates an int to be used as the encryption key for the encoding.

    3. Creates another String to hold the result of the encoding.

    1. Tests the encode method with multiple messages and encryption keys

Note: The example on the previous page shows that the message: HELLO with key: 2

results in the encoded message: JGNNQ. You must test that this is true in your solution. Another recommended follow-up test might be to make sure that the message: JGNNQ with key: –2 results in the encoded message: HELLO. The encrypt method must be completed before these tests will work.

  1. A static method called encrypt(), which does the following:

    1. Follows the algorithm outlined in the previous page to encode a message given a String and int passed in as parameters.

    1. Returns the encoded message.

  1. A static method named userInteraction(), which does the following:

    1. Creates and uses a Scanner and its nextLine() and nextInt() methods to read input from the user to get values for the message and key.

    2. Further tests the encrypt method using these values.

Advice: Build this method in parts, compiling and running after each major addition to your code to check that the code does work as you expect. For example, you might first create the String and int variables in the testing() method and then work on the encrypt() method and initially test its implementation with simple values (don’t worry about wrapping around Z right away). After that, write further tests in your testing() method and figure out the complicated cases in your encrypt() method.

File to submit: Encode.java

Marking

Your mark will be based on the following criteria:

  • Your code must compile and run. It must prompt the user, read text input, and produce the expected output as described and shown above.

  • Your code must conform to the requirements mentioned above (i.e., have testing(), encrypt() and userInteraction() methods.

  • Your code must follow the guidelines outlined in Style_Guidelines.pdf, found through the Lectures & Stuff link in the Lab Resources folder on connex.

Page 3 of 3