From 94f09616aeb061af2a7cfa6944996a1a342cc66f Mon Sep 17 00:00:00 2001 From: mo Date: Sun, 2 Jun 2019 21:38:11 -0600 Subject: add documentation. --- src/Q1/ReversedSentence.java | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/Q1/ReversedSentence.java') diff --git a/src/Q1/ReversedSentence.java b/src/Q1/ReversedSentence.java index d218c8c..dcc5259 100644 --- a/src/Q1/ReversedSentence.java +++ b/src/Q1/ReversedSentence.java @@ -1,8 +1,24 @@ +/** + * Assignment 2, COMP268 Class: ReversedSentence.java + * + * @description Provides a class to manipulating strings. + * @author: mo khan Student ID: 3431709 + * @date Jun 2, 2019 + * @version 1.0 + */ + package Q1; import java.util.Scanner; public class ReversedSentence { + /** + * Replaces the every character that is in an index that is evenly + * divisible by 5 with the character 'z', excluding 0. + * + * @param s The input string to substitue + * @return The new string with the substitution. + */ public static String change5thPosition(String s) { char[] result = new char[s.length()]; @@ -11,6 +27,12 @@ public class ReversedSentence { return new String(result); } + /** + * Combines the 2D array of character into a printable string. + * + * @param arr the two dimensional array of characters. + * @return a String of the combined character arrays separated by a line separator. + */ public static String printChar2DArray(char[][] arr) { String[] strings = new String[arr.length]; @@ -18,6 +40,12 @@ public class ReversedSentence { return String.join(System.lineSeparator(), strings); } + /** + * Reverses a string. + * + * @param s the input String to reverse + * @return the reversed String. + */ public static String reverseByCharacter(String s) { char[] result = new char[s.length()]; int length = s.length(); @@ -27,6 +55,12 @@ public class ReversedSentence { return new String(result); } + /** + * Reverses the words in a string + * + * @param s the input string to reverse + * @return a string with the words in reverse order + */ public static String reverseByWord(String s) { String[] words = s.split(" "); String[] result = new String[words.length]; @@ -38,10 +72,21 @@ public class ReversedSentence { return String.join(" ", result); } + /** + * Truncates a tring to a maximum of 80 characters. + * + * @param s the input string to truncate + * @return the truncated string + */ public static String truncateSentence(String s) { return s.substring(0, Math.min(s.length(), 80)); } + /** + * The entry point for the console application. + * + * @param args the commandline arguments passed to the program + */ public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] sentences = new String[3]; -- cgit v1.2.3