Changes and stuff
This commit is contained in:
parent
a12982b040
commit
9fba1289e3
@ -9,7 +9,7 @@ public class Vorlesung {
|
||||
private int teilnehmerzahl;
|
||||
|
||||
public Vorlesung(List<String> list) throws TextFileFormatException {
|
||||
if(list.size() <1 || list.size() > 4) throw new TextFileFormatException("invalid number of Strings in list");
|
||||
if(list.size() != 4) throw new TextFileFormatException("invalid number of Strings in list");
|
||||
this.studiengruppe = list.get(0);
|
||||
this.title = list.get(1);
|
||||
this.dozent = list.get(2);
|
||||
|
@ -28,11 +28,11 @@ public class Vorlesungsverzeichnis implements Comparator<Vorlesung>{
|
||||
*/
|
||||
private List<List<String>> load(String filename) throws IOException {
|
||||
List<List<String>> result = new ArrayList<>();
|
||||
BufferedReader br = new BufferedReader(new FileReader(filename));
|
||||
for (String line = br.readLine(); line != null; line = br.readLine())
|
||||
result.add(Arrays.asList(line.split(":")));
|
||||
br.close();
|
||||
return result;
|
||||
try(BufferedReader br = new BufferedReader(new FileReader(filename))) {
|
||||
for (String line = br.readLine(); line != null; line = br.readLine())
|
||||
result.add(Arrays.asList(line.split(":")));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,38 +0,0 @@
|
||||
package de.joethei.hs.java2.vorlesungen;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class Sieb {
|
||||
private int n;
|
||||
|
||||
public Sieb(int n) {
|
||||
this.n = n;
|
||||
}
|
||||
|
||||
public Set<Integer> getPrimzahl() {
|
||||
Set<Integer> set = new TreeSet<>();
|
||||
for(int i = 2; i <= n; i++) {
|
||||
set.add(i);
|
||||
}
|
||||
Set<Integer> not = new TreeSet<>();
|
||||
int mult;
|
||||
int number = 2;
|
||||
do{
|
||||
mult = 2*number;
|
||||
while (mult <= n) {
|
||||
not.add(mult);
|
||||
mult += number;
|
||||
}
|
||||
do {
|
||||
number++;
|
||||
}
|
||||
while (not.contains(number));
|
||||
}while (number * number <= n);
|
||||
set.removeAll(not);
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package de.joethei.hs.java2.vorlesungen.binaryTree;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Node<T> {
|
||||
|
||||
private T value;
|
||||
private Node<T> left;
|
||||
private Node<T> right;
|
||||
|
||||
private Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
||||
public Node(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Node(T value, Node<T> left, Node<T> right) {
|
||||
this.value = value;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Node<T> getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public Node<T> getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Node) {
|
||||
Node node = (Node) obj;
|
||||
if(node.value.equals(this.value) && node.left == null && node.right == null) return true;
|
||||
return node.value.equals(this.value) && node.left.equals(this.left) && node.right.equals(this.right);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package de.joethei.hs.java2.vorlesungen.binaryTree;
|
||||
|
||||
public class Tree<T> {
|
||||
|
||||
private Node<T> root;
|
||||
|
||||
public Tree(Node<T> root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public Node<T> getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
@ -80,6 +80,7 @@ public class GrosseZahlTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void wrongInput() {
|
||||
new GrosseZahl("42B");
|
||||
new GrosseZahl("42/");
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package de.joethei.hs.java2.tests;
|
||||
|
||||
import de.joethei.hs.java2.vorlesungen.Sieb;
|
||||
import de.joethei.hs.java2.vorlesungen.binaryTree.Node;
|
||||
import de.joethei.hs.java2.vorlesungen.binaryTree.Tree;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class VorlesungsTest {
|
||||
|
||||
@Test
|
||||
public void sieb() {
|
||||
Set<Integer> set = new TreeSet<>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19));
|
||||
assertEquals(set, new Sieb(20).getPrimzahl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binaryTree() {
|
||||
Tree<Integer> tree = new Tree<>(new Node<>(45, new Node<>(14), new Node<>(16)));
|
||||
Node<Integer> node = new Node<>(45, new Node<>(14), new Node<>(16));
|
||||
assertEquals(Integer.valueOf(45), tree.getRoot().getValue());
|
||||
assertEquals(Integer.valueOf(14), tree.getRoot().getLeft().getValue());
|
||||
assertEquals(Integer.valueOf(16), tree.getRoot().getRight().getValue());
|
||||
|
||||
assertEquals(tree.getRoot(), node);
|
||||
|
||||
|
||||
assertNotEquals(node, "HalloWelt");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user