From c7f88c87ac61beb4bcb59740dde6d5f06042da5b Mon Sep 17 00:00:00 2001 From: KateOrient <31737885+KateOrient@users.noreply.github.com> Date: Sun, 10 Sep 2017 00:14:39 +0300 Subject: [PATCH 1/3] Add files via upload --- Format/Format.java | 57 ++++++++++++++++++++++++++++++++++++++++- Format/myFormatText.txt | 20 +++++++++++++++ MyMain.java | 2 ++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 Format/myFormatText.txt diff --git a/Format/Format.java b/Format/Format.java index f738c8b..4fe49e8 100644 --- a/Format/Format.java +++ b/Format/Format.java @@ -33,7 +33,8 @@ public Format() { } public boolean compareToPunct(char c) { - if (c == DOT || c == COMMA || c == QUESTION || c == DASH || c == COLON || c == QUOTES || c == EXCLAMATION || c == SEMICOLON) { + if (c == DOT || c == COMMA || c == QUESTION || c == DASH || c == COLON + || c == QUOTES || c == EXCLAMATION || c == SEMICOLON) { return true; } return false; @@ -55,4 +56,58 @@ public void print() { for (int i = 0; i < wordNum; i++) System.out.println(Text[i]); } + + public void format(String fileName) throws IOException { + FileWriter writer = new FileWriter(fileName, false); + int currentWord = 0; + int firstWordInLine = 0; + final int NUM_WORDS_IN_LINE = 3; + while (firstWordInLine < wordNum) { + for (int i = firstWordInLine; i < firstWordInLine + NUM_WORDS_IN_LINE && i < wordNum; i++) { + char[] L = new char[Text[i].length()]; + Text[i].getChars(0, Text[i].length(), L, 0); + for (int j = 0; j < L.length; j++) { + if ((L[j] >= A_SMALL_CODE && L[j] <= A_SMALL_CODE + MAX_LETTER_NUMBER - 1) + || (L[j] >= A_BIG_CODE && L[j] <= A_BIG_CODE + MAX_LETTER_NUMBER - 1)) { + writer.write(" "); + } + writer.write(L[j]); + } + writer.write(" "); + } + writer.write("\r\n"); + writer.write(""); + for (int i = firstWordInLine; i < firstWordInLine + NUM_WORDS_IN_LINE && i < wordNum; i++) { + char[] L = new char[Text[i].length()]; + Text[i].getChars(0, Text[i].length(), L, 0); + for (int j = 0; j < L.length; j++) { + if ((L[j] >= A_SMALL_CODE && L[j] <= A_SMALL_CODE + MAX_LETTER_NUMBER - 1) + || (L[j] >= A_BIG_CODE && L[j] <= A_BIG_CODE + MAX_LETTER_NUMBER - 1)) { + if (L[j] < A_SMALL_CODE) { + if ((L[j] - A_BIG_CODE + 1 )/ 10 < 1) { + writer.write(" "); + } else { + writer.write(" "); + } + writer.write(""+(0 + L[j] - A_BIG_CODE + 1)); + } + else { + if ((L[j] - A_SMALL_CODE + 1 )/ 10 < 1) { + writer.write(" "); + } else { + writer.write(" "); + } + writer.write("" + (0 + L[j] - A_SMALL_CODE + 1)); + } + } else + writer.write(" "); + } + writer.write(" "); + } + writer.write("\r\n"); + firstWordInLine += NUM_WORDS_IN_LINE; + currentWord += NUM_WORDS_IN_LINE; + } + writer.close(); + } } diff --git a/Format/myFormatText.txt b/Format/myFormatText.txt new file mode 100644 index 0000000..6671c00 --- /dev/null +++ b/Format/myFormatText.txt @@ -0,0 +1,20 @@ + H e l l o! M y n a m e + 8 5 12 12 15 13 25 14 1 13 5 + i s K a t e. I' m + 9 19 11 1 20 5 9 13 + a s e c o n d y e a r + 1 19 5 3 15 14 4 25 5 1 18 + s t u d e n t o f t h e + 19 20 21 4 5 14 20 15 6 20 8 5 + B e l a r u s i a n S t a t e U n i v e r s i t y + 2 5 12 1 18 21 19 9 1 14 19 20 1 20 5 21 14 9 22 5 18 19 9 20 25 + t h e F a c u l t y o f + 20 8 5 6 1 3 21 12 20 25 15 6 + A p p l i e d M a t h e m a t i c s a n d + 1 16 16 12 9 5 4 13 1 20 8 5 13 1 20 9 3 19 1 14 4 + C o m p u t e r S c i e n c e. I + 3 15 13 16 21 20 5 18 19 3 9 5 14 3 5 9 + r e a l l y e n g o y s t u d y i n g + 18 5 1 12 12 25 5 14 7 15 25 19 20 21 4 25 9 14 7 + h e r e. + 8 5 18 5 diff --git a/MyMain.java b/MyMain.java index fe4d3d8..6964694 100644 --- a/MyMain.java +++ b/MyMain.java @@ -7,5 +7,7 @@ public static void main(String[] args) throws IOException{ Format f = new Format(); f.loadText("C:\\Users\\Kate\\IdeaProjects\\program5\\src\\Format\\myText.txt"); f.print(); + System.out.println(); + f.format("C:\\Users\\Kate\\IdeaProjects\\program5\\src\\Format\\myFormatText.txt"); } } From 5d336f3737b7210f6f8e3c1a5010afeb3ee35102 Mon Sep 17 00:00:00 2001 From: KateOrient <31737885+KateOrient@users.noreply.github.com> Date: Sun, 10 Sep 2017 16:50:34 +0300 Subject: [PATCH 2/3] Add files via upload --- Format/Format.java | 88 ++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/Format/Format.java b/Format/Format.java index 4fe49e8..7ff7e9a 100644 --- a/Format/Format.java +++ b/Format/Format.java @@ -9,7 +9,7 @@ public class Format { final int A_BIG_CODE; final int MAX_LETTER_NUMBER_IN_LINE; final int MAX_WORD_NUMBER; - final char DOT, COMMA, EXCLAMATION, QUESTION, DASH, COLON, QUOTES, SEMICOLON; + final int NUM_WORDS_IN_LINE; String[] Text; int wordNum; @@ -20,26 +20,11 @@ public Format() { A_BIG_CODE = 65; MAX_LETTER_NUMBER_IN_LINE = 20; MAX_WORD_NUMBER = 200; - DOT = '.'; - COMMA = ','; - QUESTION = '?'; - DASH = '-'; - COLON = ':'; - QUOTES = '"'; - EXCLAMATION = '!'; - SEMICOLON = ';'; + NUM_WORDS_IN_LINE = 3; Text = new String[MAX_WORD_NUMBER]; wordNum = 0; } - public boolean compareToPunct(char c) { - if (c == DOT || c == COMMA || c == QUESTION || c == DASH || c == COLON - || c == QUOTES || c == EXCLAMATION || c == SEMICOLON) { - return true; - } - return false; - } - public void loadText(String fileName) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(fileName)); String s; @@ -57,18 +42,55 @@ public void print() { System.out.println(Text[i]); } + boolean isALetter(char c) { + if ((c >= A_SMALL_CODE && c <= A_SMALL_CODE + MAX_LETTER_NUMBER - 1) + || ((c >= A_BIG_CODE && c <= A_BIG_CODE + MAX_LETTER_NUMBER - 1))) { + return true; + } + return false; + } + + boolean isUppercase(char c) { + if (isALetter(c) && c < A_SMALL_CODE) { + return true; + } + return false; + } + + int getNumInAlph(char c) { + if (isALetter(c)) { + if (isUppercase(c)) { + return (c - A_BIG_CODE + 1); + } else { + return (c - A_SMALL_CODE + 1); + } + } + return 0; + } + + boolean isOneSignedNumberInAlph(char c) { + if (isUppercase(c)) { + if (getNumInAlph(c) / 10 < 1) + return true; + else + return false; + } else { + if (getNumInAlph(c) / 10 < 1) + return true; + else + return false; + } + } + public void format(String fileName) throws IOException { FileWriter writer = new FileWriter(fileName, false); - int currentWord = 0; int firstWordInLine = 0; - final int NUM_WORDS_IN_LINE = 3; while (firstWordInLine < wordNum) { for (int i = firstWordInLine; i < firstWordInLine + NUM_WORDS_IN_LINE && i < wordNum; i++) { char[] L = new char[Text[i].length()]; Text[i].getChars(0, Text[i].length(), L, 0); for (int j = 0; j < L.length; j++) { - if ((L[j] >= A_SMALL_CODE && L[j] <= A_SMALL_CODE + MAX_LETTER_NUMBER - 1) - || (L[j] >= A_BIG_CODE && L[j] <= A_BIG_CODE + MAX_LETTER_NUMBER - 1)) { + if (isALetter((L[j]))) { writer.write(" "); } writer.write(L[j]); @@ -81,24 +103,13 @@ public void format(String fileName) throws IOException { char[] L = new char[Text[i].length()]; Text[i].getChars(0, Text[i].length(), L, 0); for (int j = 0; j < L.length; j++) { - if ((L[j] >= A_SMALL_CODE && L[j] <= A_SMALL_CODE + MAX_LETTER_NUMBER - 1) - || (L[j] >= A_BIG_CODE && L[j] <= A_BIG_CODE + MAX_LETTER_NUMBER - 1)) { - if (L[j] < A_SMALL_CODE) { - if ((L[j] - A_BIG_CODE + 1 )/ 10 < 1) { - writer.write(" "); - } else { - writer.write(" "); - } - writer.write(""+(0 + L[j] - A_BIG_CODE + 1)); - } - else { - if ((L[j] - A_SMALL_CODE + 1 )/ 10 < 1) { - writer.write(" "); - } else { - writer.write(" "); - } - writer.write("" + (0 + L[j] - A_SMALL_CODE + 1)); + if (isALetter((L[j]))) { + if (isOneSignedNumberInAlph(L[j])) { + writer.write(" "); + } else { + writer.write(" "); } + writer.write("" + getNumInAlph(L[j])); } else writer.write(" "); } @@ -106,7 +117,6 @@ public void format(String fileName) throws IOException { } writer.write("\r\n"); firstWordInLine += NUM_WORDS_IN_LINE; - currentWord += NUM_WORDS_IN_LINE; } writer.close(); } From f5c0761b42cb0ec45dda3c45f53120cbe40e40b2 Mon Sep 17 00:00:00 2001 From: KateOrient <31737885+KateOrient@users.noreply.github.com> Date: Sun, 10 Sep 2017 16:58:20 +0300 Subject: [PATCH 3/3] Add files via upload --- Format/Format.java | 1 - Format/myFormatText.txt | 8 ++++++-- Format/myText.txt | 2 +- MyMain.java | 2 -- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Format/Format.java b/Format/Format.java index 7ff7e9a..aabe19f 100644 --- a/Format/Format.java +++ b/Format/Format.java @@ -98,7 +98,6 @@ public void format(String fileName) throws IOException { writer.write(" "); } writer.write("\r\n"); - writer.write(""); for (int i = firstWordInLine; i < firstWordInLine + NUM_WORDS_IN_LINE && i < wordNum; i++) { char[] L = new char[Text[i].length()]; Text[i].getChars(0, Text[i].length(), L, 0); diff --git a/Format/myFormatText.txt b/Format/myFormatText.txt index 6671c00..8fcc41b 100644 --- a/Format/myFormatText.txt +++ b/Format/myFormatText.txt @@ -16,5 +16,9 @@ 3 15 13 16 21 20 5 18 19 3 9 5 14 3 5 9 r e a l l y e n g o y s t u d y i n g 18 5 1 12 12 25 5 14 7 15 25 19 20 21 4 25 9 14 7 - h e r e. - 8 5 18 5 + h e r e. M y f a v o r i t e + 8 5 18 5 13 25 6 1 22 15 18 9 20 5 + s u b j e c t s a r e m a t h e m a t i c a l + 19 21 2 10 5 3 20 19 1 18 5 13 1 20 8 5 13 1 20 9 3 1 12 + a n a l y s i s a n d p r o g r a m i n g. + 1 14 1 12 25 19 9 19 1 14 4 16 18 15 7 18 1 13 9 14 7 diff --git a/Format/myText.txt b/Format/myText.txt index fa5f2bf..f06c0f7 100644 --- a/Format/myText.txt +++ b/Format/myText.txt @@ -1 +1 @@ -Hello! My name is Kate. I'm a second year student of the Belarusian State University the Faculty of Applied Mathematics and Computer Science. I really engoy studying here. \ No newline at end of file +Hello! My name is Kate. I'm a second year student of the Belarusian State University the Faculty of Applied Mathematics and Computer Science. I really engoy studying here. My favorite subjects are mathematical analysis and programing. \ No newline at end of file diff --git a/MyMain.java b/MyMain.java index 6964694..c555572 100644 --- a/MyMain.java +++ b/MyMain.java @@ -6,8 +6,6 @@ public class MyMain { public static void main(String[] args) throws IOException{ Format f = new Format(); f.loadText("C:\\Users\\Kate\\IdeaProjects\\program5\\src\\Format\\myText.txt"); - f.print(); - System.out.println(); f.format("C:\\Users\\Kate\\IdeaProjects\\program5\\src\\Format\\myFormatText.txt"); } }