Преглед изворни кода

DOSSSSSSSSSSSSSSSSSSSSSSSSSSSS

Ahmad Rusdi пре 6 година
родитељ
комит
175219d629

+ 1
- 1
.idea/vcs.xml Прегледај датотеку

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3 3
   <component name="VcsDirectoryMappings">
4
-    <mapping directory="" vcs="Git" />
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5 5
   </component>
6 6
 </project>

+ 16
- 0
pom.xml Прегледај датотеку

@@ -3,7 +3,23 @@
3 3
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 4
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 5
     <modelVersion>4.0.0</modelVersion>
6
+    <build>
7
+        <plugins>
8
+            <plugin>
9
+                <groupId>org.apache.maven.plugins</groupId>
10
+                <artifactId>maven-compiler-plugin</artifactId>
11
+                <configuration>
12
+                    <source>8</source>
13
+                    <target>8</target>
14
+                </configuration>
15
+            </plugin>
16
+        </plugins>
17
+    </build>
6 18
 
19
+    <properties>
20
+        <maven.compiler.source>1.8</maven.compiler.source>
21
+        <maven.compiler.target>1.8</maven.compiler.target>
22
+    </properties>
7 23
     <groupId>io.zipcoder</groupId>
8 24
     <artifactId>FundamentalDrillsPart2</artifactId>
9 25
     <version>1.0-SNAPSHOT</version>

+ 42
- 5
src/main/java/io/zipcoder/StringsAndThings.java Прегледај датотеку

@@ -1,5 +1,8 @@
1 1
 package io.zipcoder;
2 2
 
3
+import java.util.Arrays;
4
+import java.util.List;
5
+
3 6
 public class StringsAndThings {
4 7
 
5 8
     /**
@@ -11,7 +14,14 @@ public class StringsAndThings {
11 14
      *           countYZ("day fyyyz"); // Should return 2
12 15
      */
13 16
     public Integer countYZ(String input){
14
-        return null;
17
+        int count = 0;
18
+        for (String e : input.split(" ")) {
19
+            if (Character.toString(e.charAt(e.length() - 1)).equals("y") ||
20
+                Character.toString(e.charAt(e.length() - 1)).equals("z")) {
21
+                count++;
22
+            }
23
+        }
24
+        return count;
15 25
     }
16 26
 
17 27
     /**
@@ -24,7 +34,7 @@ public class StringsAndThings {
24 34
      *           withoutString("Hello there", "x") // Should return "Hello there"
25 35
      */
26 36
     public String withoutString(String base, String remove){
27
-        return null;
37
+        return base.replace(remove, "");
28 38
     }
29 39
 
30 40
     /**
@@ -36,7 +46,26 @@ public class StringsAndThings {
36 46
      *           equalIsNot("noisxxnotyynotxisi") // Should return true
37 47
      */
38 48
     public Boolean equalIsNot(String input){
39
-        return null;
49
+        int isCount = 0;
50
+        int isIdx = 0;
51
+        while (isIdx != -1) {
52
+            isIdx = input.indexOf("is", ++isIdx);
53
+            if (isIdx != -1) {
54
+                isCount++;
55
+                isIdx++;
56
+            }
57
+        }
58
+
59
+        int notCount = 0;
60
+        isIdx = 0;
61
+        while (isIdx != -1) {
62
+            isIdx = input.indexOf("not", ++isIdx);
63
+            if (isIdx != -1) {
64
+                notCount++;
65
+                isIdx++;
66
+            }
67
+        }
68
+        return isCount == notCount;
40 69
     }
41 70
 
42 71
     /**
@@ -47,7 +76,7 @@ public class StringsAndThings {
47 76
      *           gHappy("xxggyygxx") // Should return  false
48 77
      */
49 78
     public Boolean gIsHappy(String input){
50
-        return null;
79
+        return !input.replaceAll("gg+", "").contains("g");
51 80
     }
52 81
 
53 82
 
@@ -59,6 +88,14 @@ public class StringsAndThings {
59 88
      *            countTriple("a") // Should return 0
60 89
      */
61 90
     public Integer countTriple(String input){
62
-        return null;
91
+        int count = 0;
92
+
93
+        for(int i = 0; i <= input.length() - 3; i++) {
94
+            if(input.charAt(i) == input.charAt(i+1) &&
95
+                    input.charAt(i) == input.charAt(i+2))
96
+                count++;
97
+        }
98
+
99
+        return count;
63 100
     }
64 101
 }

+ 1
- 1
src/test/java/io/zipcoder/StringsAndThingsTest.java Прегледај датотеку

@@ -92,7 +92,7 @@ public class StringsAndThingsTest {
92 92
     @Test
93 93
     public void gIsHappyTest3(){
94 94
         Boolean actual = stringsAndThings.gIsHappy("xxggyygxx");
95
-        Assert.assertTrue(actual);
95
+        Assert.assertFalse(actual);
96 96
     }
97 97
 
98 98
     @Test

BIN
target/classes/io/zipcoder/StringsAndThings.class Прегледај датотеку


BIN
target/test-classes/io/zipcoder/StringsAndThingsTest.class Прегледај датотеку