From 43d6922d68636b20335ba34fe552956d2d8fcdde Mon Sep 17 00:00:00 2001 From: Joshua Curtiss Date: Mon, 18 Mar 2024 23:58:39 -0700 Subject: [PATCH] program runs as expected --- .idea/deployment.xml | 14 ++++++++++ .idea/vcs.xml | 6 +++++ src/Main.java | 64 +++++++++++++++++++++++++++++++++++++++----- 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 .idea/deployment.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..b1f0de0 --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ 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..6903605 100644 --- a/src/Main.java +++ b/src/Main.java @@ -41,32 +41,82 @@ public class Main { public static void main(String[] args) { //TIP Press with your caret at the highlighted text // to see how IntelliJ IDEA suggests fixing it. - System.out.println("Hello and welcome!"); + // set up empty buffer, size of 0 char[] buffer = new char[BUFFER_CAPACITY]; - int size = 0; + int size; + + System.out.println("Hello and welcome!"); + // initialize the buffer and size variables with some data + String temp1 = "Hello and welcome!"; + for (int i = 0; i < temp1.length(); i++) { + buffer[i] = temp1.charAt(i); + } + size = temp1.length(); + + whiteSpaceReplacer(size, buffer); + // check the "after" buffer contents via println + // check to see if the new buffer's size is correct + System.out.println(buffer); + // initialize the buffer and size variables with some data - String temp = "Dr Martin Luther King"; - for (int i = 0; i < temp.length(); i++) { - buffer[i] = temp.charAt(i); + System.out.println("Dr Martin Luther King"); + String temp2 = "Dr Martin Luther King"; + for (int i = 0; i < temp2.length(); i++) { + buffer[i] = temp2.charAt(i); } - size = temp.length(); + size = temp2.length(); // check the "before" buffer and size via println System.out.println(Arrays.toString(buffer)); System.out.println("size: " + size); // call your method here - + whiteSpaceReplacer(size, buffer); // check the "after" buffer contents via println // check to see if the new buffer's size is correct + System.out.println(buffer); + //Above should be pushed into a method. but the files didn't establish them that way. } // write your method here + private static void whiteSpaceReplacer(int size, char[] buffer){ + int countSpace = 0; + for(int i = 0; i= 0; i--){ + //if buffer position is a white space add % to newPosition, 2 to newPosition -1, % to new position -3 + //Move the new position by 3 points INSTEAD of 1. + if(buffer[i] == ' '){ + buffer[newPosition] = '0'; + buffer[newPosition-1] = '2'; + buffer[newPosition-2] = '%'; + //move new position by 3 positions. + newPosition -= 3; + } + else if (newPosition != 0){ + //move characters from old index positions to new index positions. + buffer[newPosition] = buffer[i]; + //shift new position by 1 value to fill in the next box + newPosition--; + } + } + } } \ No newline at end of file