+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 6f29fee..5c02e7d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
index 0282a9d..479ab2b 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -35,9 +35,19 @@ with a buffer (similar to how a resizable ArrayList, and/or a
import java.util.Arrays;
+/**
+ * The main class to run the main method
+ * @author Huy Nguyen
+ * @version 1.0
+ */
+
public class Main {
public static final int BUFFER_CAPACITY = 32768;
+ /**
+ * The main method of java
+ * @param args string arguments of main method
+ */
public static void main(String[] args) {
//TIP Press with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
@@ -59,14 +69,54 @@ public static void main(String[] args) {
System.out.println("size: " + size);
// call your method here
-
+ urlify(buffer, size);
// check the "after" buffer contents via println
+ System.out.println(Arrays.toString(buffer));
// check to see if the new buffer's size is correct
-
-
+ size=0;
+ for (int i = 0; i < buffer.length; i++) {
+ //not equals to null
+ if (buffer[i] != '\u0000'){
+ size++;
+ }
+ }
+ System.out.println("Size: " + size);
}
+
// write your method here
+ /**
+ * The urlify method to add '%20' at every space and increment the size
+ *
+ * @param buffer the char[] which is being manipulated
+ * @param size current size of the buffer
+ * @return
+ */
+ public static char[] urlify(char[] buffer, int size){
+ int spaceSize = 0;
+ for (int i = 0; i < size; i++) {
+ if (buffer[i] == ' ') {
+ spaceSize++;
+ }
+ }
+ // Calculate the size after adding in %20 in blank spaces
+ int maxSizePointer = size + spaceSize * 2;
+ System.out.println("Buffer Size: " + maxSizePointer);
+ for (int i = size - 1; i >= 0; i--) {
+ if (buffer[i] == ' ') {
+ //if there is a blank space, replace with %20 relative to the maxSizePointer at the back
+ buffer[maxSizePointer - 1] = '0';
+ buffer[maxSizePointer - 2] = '2';
+ buffer[maxSizePointer - 3] = '%';
+ maxSizePointer -= 3;
+ } else {
+ //if letter, place within their location relative to maxSizePointer at the back
+ buffer[maxSizePointer - 1] = buffer[i];
+ maxSizePointer--;
+ }
+ }
+ return buffer;
+ }
}
\ No newline at end of file