Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 80 additions & 16 deletions Format/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,25 +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;
Expand All @@ -55,4 +41,82 @@ public void print() {
for (int i = 0; i < wordNum; i++)
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 firstWordInLine = 0;
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 (isALetter((L[j]))) {
writer.write(" ");
}
writer.write(L[j]);
}
writer.write(" ");
}
writer.write("\r\n");
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 (isALetter((L[j]))) {
if (isOneSignedNumberInAlph(L[j])) {
writer.write(" ");
} else {
writer.write(" ");
}
writer.write("" + getNumInAlph(L[j]));
} else
writer.write(" ");
}
writer.write(" ");
}
writer.write("\r\n");
firstWordInLine += NUM_WORDS_IN_LINE;
}
writer.close();
}
}
24 changes: 24 additions & 0 deletions Format/myFormatText.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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. 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
2 changes: 1 addition & 1 deletion Format/myText.txt
Original file line number Diff line number Diff line change
@@ -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.
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.
2 changes: 1 addition & 1 deletion MyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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();
f.format("C:\\Users\\Kate\\IdeaProjects\\program5\\src\\Format\\myFormatText.txt");
}
}