This commit is contained in:
Johannes Theiner 2018-04-06 13:09:50 +02:00
parent 689253c1fb
commit 344484735f
2 changed files with 11 additions and 5 deletions

View File

@ -1,15 +1,20 @@
package de.joethei.hs.java2.praktikum.praktikum2; package de.joethei.hs.java2.praktikum.praktikum2;
import java.util.*; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class CharCollection { public class CharCollection {
ArrayList<Character> list = new ArrayList<>(); ArrayList<Character> list = new ArrayList<>();
public CharCollection(char... cc) { public CharCollection(char... cc) {
for(char c:cc) this.list.add(c); for(char c:cc) this.list.add(c);
} }
public CharCollection(String s) { public CharCollection(String s) {
new CharCollection(s.toCharArray()); for(char c : s.toCharArray()) {
this.list.add(c);
}
} }
@ -44,6 +49,6 @@ public class CharCollection {
}*/ }*/
public String toString() { public String toString() {
return list.toString(); return list.toString().replace('[', '(').replace(']', ')');
} }
} }

View File

@ -32,11 +32,12 @@ public class CharCollectionTest {
public void top() { public void top() {
assertEquals('l', new CharCollection("Hallo").top()); assertEquals('l', new CharCollection("Hallo").top());
} }
*/
@Test @Test
public void toStringTest() { public void toStringTest() {
assertEquals("HalloWelt", new CharCollection("HalloWelt").toString()); assertEquals("(H, a, l, l, o, W, e, l, t)", new CharCollection("HalloWelt").toString());
} }
/*
@Test @Test
public void moreThan() { public void moreThan() {