Browse Source

all the classes can write.

Whitney Martinez 7 years ago
parent
commit
9ea0c40148

+ 15
- 8
src/main/java/rocks/zipcode/AlphaCharDocument.java View File

@@ -1,14 +1,12 @@
1 1
 package rocks.zipcode;
2 2
 
3
-import java.io.BufferedWriter;
4
-import java.io.FileWriter;
5
-import java.io.IOException;
3
+import java.io.*;
4
+import java.util.regex.Pattern;
6 5
 
7 6
 /**
8 7
  * @author leon on 16/11/2018.
9 8
  */
10 9
 public class AlphaCharDocument extends Document {
11
-    Document document;
12 10
 
13 11
     public AlphaCharDocument(String fileName) throws IOException {
14 12
 
@@ -18,15 +16,24 @@ public class AlphaCharDocument extends Document {
18 16
 
19 17
     @Override
20 18
     public void write(String contentToBeWritten) throws IOException {
21
-
22
-     
19
+        BufferedWriter writer = new BufferedWriter(new FileWriter("target/file.txt"));
20
+        writer.write(contentToBeWritten);
21
+        writer.close();
23 22
 
24 23
     }
25 24
 
26 25
     private Boolean isAlpha(String s) {
27 26
 
28
-        boolean allLetters = s.chars().allMatch(Character::isLetter);
29
-        return allLetters;
27
+//        boolean allLetters = s.chars().allMatch(Character::isLetter);
28
+//        return allLetters;
29
+
30
+
31
+//        return (s.matches("[a-zA-Z]+"));
32
+
33
+        if(! Pattern.matches(".*[a-zA-Z]+.*", s))
34
+            return true;
35
+        else return false;
36
+
30 37
 
31 38
     }
32 39
 

+ 7
- 0
src/main/java/rocks/zipcode/Document.java View File

@@ -95,6 +95,13 @@ public class Document implements DocumentInterface {
95 95
 
96 96
     @Override
97 97
     public void overWrite(String content) {
98
+
99
+        try {
100
+            Writer fileWriter = new FileWriter("target/file.txt", false);
101
+            write(content);
102
+        } catch (IOException e) {
103
+            e.printStackTrace();
104
+        }
98 105
     }
99 106
 
100 107
     public List<String> toList() {

+ 10
- 2
src/main/java/rocks/zipcode/NumericCharDocument.java View File

@@ -1,6 +1,9 @@
1 1
 package rocks.zipcode;
2 2
 
3
+import java.io.BufferedWriter;
4
+import java.io.FileWriter;
3 5
 import java.io.IOException;
6
+import java.util.regex.Pattern;
4 7
 
5 8
 /**
6 9
  * @author leon on 16/11/2018.
@@ -11,10 +14,15 @@ public class NumericCharDocument extends Document {
11 14
     }
12 15
 
13 16
     @Override
14
-    public void write(String contentToBeWritten) {
17
+    public void write(String contentToBeWritten) throws IOException {
18
+        BufferedWriter writer = new BufferedWriter(new FileWriter("target/file.txt"));
19
+        writer.write(contentToBeWritten);
20
+        writer.close();
15 21
     }
16 22
 
17 23
     private Boolean isNumeric(String s) {
18
-        return null;
24
+
25
+
26
+        return false;
19 27
     }
20 28
 }

+ 7
- 1
src/main/java/rocks/zipcode/SpecialCharDocument.java View File

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode;
2 2
 
3
+import java.io.BufferedWriter;
4
+import java.io.FileWriter;
3 5
 import java.io.IOException;
4 6
 
5 7
 /**
@@ -11,10 +13,14 @@ public class SpecialCharDocument extends Document {
11 13
     }
12 14
 
13 15
     @Override
14
-    public void write(String contentToBeWritten) {
16
+    public void write(String contentToBeWritten) throws IOException {
17
+        BufferedWriter writer = new BufferedWriter(new FileWriter("target/file.txt"));
18
+        writer.write(contentToBeWritten);
19
+        writer.close();
15 20
     }
16 21
 
17 22
     private Boolean isSpecialCharacters(String s) {
23
+
18 24
         return null;
19 25
     }
20 26
 }