master

Learning Profile for Assignment #2, And Question #1

Name: Mo Khan Student ID: 3431709

  1. Problem Statement:

Read three sentences from the console application. Each sentence should not exceed 80 characters. Then, copy each character in each input sentence in a [3 x 80] character array.

  • The first sentence should be loaded into the first row in the reverse order of characters – for example, “mary had a little lamb” should be loaded into the array as “bmal elttil a dah yram”.
  • The second sentence should be loaded into the second row in the reverse order of words – for example, “mary had a little lamb” should be loaded into the array as “lamb little a had mary”.
  • The third sentence should be loaded into the third row where if the index of the array is divisible by 5, then the corresponding character is replaced by the letter ‘z’ – for example, “mary had a little lamb” should be loaded into the array as “mary zad azlittze lazb” – that is, characters in index positions 5, 10, 15, and 20 were replaced by ‘z’.

Note that an empty space is also a character, and that the index starts from position 0. Now print the contents of the character array on the console.

  1. Description of the Code:

The API for this code uses several static methods. Each static methods takes an input string or character matrix as an input argument.

The code depends on constructing new instances of strings to perform substitutions or reversing operations.

If more than 80 characters is provided as input the string is truncated to the first 80 characters provided. The remaining characters are abondoned. It is assumed that the person entering the sentence will enter sentences that are 80 characters or less.

  1. Errors and Warnings:
    • Program compiles OK using maven and vim
    • Unit tests pass using maven.
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< ca.mokhan.comp268:assignment2 >--------------------
[INFO] Building assignment2 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- fmt-maven-plugin:2.8:format (default) @ assignment2 ---
[INFO] Processed 7 files (0 reformatted).
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ assignment2 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mokha/development/comp-268/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ assignment2 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 4 source files to /home/mokha/development/comp-268/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ assignment2 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mokha/development/comp-268/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ assignment2 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 4 source files to /home/mokha/development/comp-268/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ assignment2 ---
[INFO] Surefire report directory: /home/mokha/development/comp-268/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running ca.mokhan.test.ReversedSentenceTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 sec
Running ca.mokhan.comp268.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec

Results :

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ assignment2 ---
[INFO] Building jar: /home/mokha/development/comp-268/target/assignment2-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.183 s
[INFO] Finished at: 2019-06-02T21:46:13-06:00
[INFO] ------------------------------------------------------------------------
  1. Sample Input and Output:
    • Manually running the program with valid input.
モ mvn package
モ java -cp target/assignment2*.jar ca.mokhan.comp268.App 1
Enter sentence 1: (max 80 characters)
mary had a little lamb
Enter sentence 2: (max 80 characters)
mary had a little lamb
Enter sentence 3: (max 80 characters)
mary had a little lamb

Result: 

bmal elttil a dah yram
lamb little a had mary
mary zad azlittze lazb

Bye
    • Manually running the program with input greater than 80 characters.
モ mvn package
モ java -cp target/assignment2*.jar ca.mokhan.comp268.App 1
Enter sentence 1: (max 80 characters)
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Enter sentence 2: (max 80 characters)
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Enter sentence 3: (max 80 characters)
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

Result: 

09876543210987654321098765432109876543210987654321098765432109876543210987654321
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345z7890z2345z7890z2345z7890z2345z7890z2345z7890z2345z7890z2345z7890z2345z7890

Bye
    • Manually running the program with no input
モ mvn package
モ java -cp target/assignment2*.jar ca.mokhan.comp268.App 1
Enter sentence 1: (max 80 characters)

Enter sentence 2: (max 80 characters)

Enter sentence 3: (max 80 characters)


Result: 





Bye
  1. Discussion:

I started implementing this exercise by creating a class that matches the supplied class diagram in the assignment. I then started writing tests using junit to flush out the expected API.

I only wrote happy path tests using junit, but this was enough to put together a running console application.

I chose to use maven to create the default folder structure and used maven plugins to run junit and to automatically format the code as per the Google java code style guidelines.