From 344484735fa40dfd0fbfff459a41f28bf0ebbd85 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Fri, 6 Apr 2018 13:09:50 +0200 Subject: [PATCH] jgoraho --- .../hs/java2/praktikum/praktikum2/CharCollection.java | 11 ++++++++--- .../de/joethei/hs/java2/tests/CharCollectionTest.java | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java index 481faaf..017d7ba 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java @@ -1,15 +1,20 @@ 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 { + ArrayList list = new ArrayList<>(); public CharCollection(char... cc) { for(char c:cc) this.list.add(c); } 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() { - return list.toString(); + return list.toString().replace('[', '(').replace(']', ')'); } } \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java b/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java index b76b11d..c6e15f1 100644 --- a/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java @@ -32,11 +32,12 @@ public class CharCollectionTest { public void top() { assertEquals('l', new CharCollection("Hallo").top()); } - + */ @Test public void toStringTest() { - assertEquals("HalloWelt", new CharCollection("HalloWelt").toString()); + assertEquals("(H, a, l, l, o, W, e, l, t)", new CharCollection("HalloWelt").toString()); } + /* @Test public void moreThan() {