sollte beliebter bei den Tools sein,

außerdem letzer commit morgen Prüfung
This commit is contained in:
Johannes Theiner 2018-06-24 19:55:14 +02:00
parent 9e4de004e6
commit 62f4018a68
3 changed files with 43 additions and 27 deletions

View File

@ -2,7 +2,7 @@ package de.joethei.hs.java2.praktikum.praktikum1;
public class GrosseZahl { public class GrosseZahl {
private int zahl[]; private int[] zahl;
public GrosseZahl(String d) { public GrosseZahl(String d) {
Boolean korrekteEingabe=true; Boolean korrekteEingabe=true;
@ -37,7 +37,8 @@ public class GrosseZahl {
public GrosseZahl add(GrosseZahl b) { public GrosseZahl add(GrosseZahl b) {
int uebertrag = 0; int uebertrag = 0;
GrosseZahl rueckgabe, operand; GrosseZahl rueckgabe;
GrosseZahl operand;
if(this.less(b)) { if(this.less(b)) {
rueckgabe = new GrosseZahl(b.toString()); rueckgabe = new GrosseZahl(b.toString());
operand = new GrosseZahl(this.toString()); operand = new GrosseZahl(this.toString());
@ -65,9 +66,7 @@ public class GrosseZahl {
public GrosseZahl sub(GrosseZahl b) { public GrosseZahl sub(GrosseZahl b) {
int uebertrag = 0; int uebertrag = 0;
StringBuilder x; StringBuilder x;
if(this.equals(b)) { if(this.equals(b) || this.less(b)) {
return new GrosseZahl(0);
} else if(this.less(b)) {
return new GrosseZahl(0); return new GrosseZahl(0);
} }
GrosseZahl rueckgabe = new GrosseZahl(this.toString()); GrosseZahl rueckgabe = new GrosseZahl(this.toString());
@ -94,8 +93,11 @@ public class GrosseZahl {
} }
public GrosseZahl mult(GrosseZahl b) { public GrosseZahl mult(GrosseZahl b) {
GrosseZahl rueckgabe, rueckgabe_b, operand, operand2; GrosseZahl rueckgabe;
rueckgabe_b = new GrosseZahl(0); GrosseZahl result;
GrosseZahl operand;
GrosseZahl operand2;
result = new GrosseZahl(0);
if(this.less(b)) { if(this.less(b)) {
operand2 = b; operand2 = b;
operand = this; operand = this;
@ -108,12 +110,12 @@ public class GrosseZahl {
for(int w = 0; w<operand.zahl[i]; w++) { for(int w = 0; w<operand.zahl[i]; w++) {
rueckgabe = rueckgabe.add(operand2); rueckgabe = rueckgabe.add(operand2);
} }
rueckgabe_b = rueckgabe_b.add(rueckgabe); result = result.add(rueckgabe);
if(i != operand.zahl.length-1) { if(i != operand.zahl.length-1) {
rueckgabe_b = new GrosseZahl(rueckgabe_b.toString()+"0"); result = new GrosseZahl(result.toString()+"0");
} }
} }
return rueckgabe_b; return result;
} }
@ -156,4 +158,8 @@ public class GrosseZahl {
return false; return false;
} }
@Override
public int hashCode() {
return super.hashCode();
}
} }

View File

@ -63,7 +63,7 @@ public class CharCollection implements Cloneable{
} }
public CharCollection except(CharCollection cc) { public CharCollection except(CharCollection cc) {
ArrayList<Character> list= new ArrayList<>(this.list); ArrayList<Character> list = new ArrayList<>(this.list);
boolean removeCharacterOnce = false; boolean removeCharacterOnce = false;
for(int i=0; i<list.size(); i++){ for(int i=0; i<list.size(); i++){
for(int w=0; w<cc.list.size(); w++) { for(int w=0; w<cc.list.size(); w++) {
@ -104,4 +104,8 @@ public class CharCollection implements Cloneable{
}return false; }return false;
} }
@Override
public int hashCode() {
return super.hashCode();
}
} }

View File

@ -4,6 +4,7 @@ import java.io.*;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.logging.Logger;
public class KlausurenServer { public class KlausurenServer {
@ -11,11 +12,17 @@ public class KlausurenServer {
private ExecutorService executorService = Executors.newCachedThreadPool(); private ExecutorService executorService = Executors.newCachedThreadPool();
private ServerSocket serverSocket; private ServerSocket serverSocket;
private static Logger logger = Logger.getLogger("KlausurenServer");
private static Map<String, CommandHandler> commands = new HashMap<>(); private static Map<String, CommandHandler> commands = new HashMap<>();
static Map<String, CommandHandler> getCommands() { static Map<String, CommandHandler> getCommands() {
return commands; return commands;
} }
public static Logger getLogger() {
return logger;
}
private boolean running; private boolean running;
public KlausurenServer(int port) { public KlausurenServer(int port) {
@ -52,8 +59,7 @@ public class KlausurenServer {
Set<TreeSet<Integer>> result = new HashSet<>(); Set<TreeSet<Integer>> result = new HashSet<>();
set.forEach((key, value) -> set.forEach((s, integers) -> { set.forEach((key, value) -> set.forEach((s, integers) -> {
if(!value.equals(integers)) { if (!value.equals(integers) && integers.containsAll(value)) {
if (integers.containsAll(value))
set.remove(key); set.remove(key);
} }
})); }));
@ -62,7 +68,7 @@ public class KlausurenServer {
result.removeIf(TreeSet::isEmpty); result.removeIf(TreeSet::isEmpty);
writer.write(result.toString().substring(1, result.toString().length()-1).replace(" ", "")); writer.write(result.toString().substring(1, result.toString().length() - 1).replace(" ", ""));
} else { } else {
writer.write("0"); writer.write("0");
} }
@ -91,7 +97,7 @@ public class KlausurenServer {
Runnable runnable = () -> { Runnable runnable = () -> {
try { try {
serverSocket = new ServerSocket(port); serverSocket = new ServerSocket(port);
System.out.println("waiting for clients"); logger.info("waiting for clients");
while (running) { while (running) {
executorService.submit(new ClientRunnable(serverSocket.accept())); executorService.submit(new ClientRunnable(serverSocket.accept()));
} }
@ -103,10 +109,10 @@ public class KlausurenServer {
} }
serverSocket.close(); serverSocket.close();
System.out.println("server shutdown"); logger.info("server shutdown");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.throwing("KlausurenServer", "Constructor", e.getCause());
} }
}; };
@ -114,12 +120,12 @@ public class KlausurenServer {
thread.start(); thread.start();
} }
synchronized void load() { private synchronized void load() {
FileReader fileReader = null; FileReader fileReader = null;
try { try {
fileReader = new FileReader(getClass().getClassLoader().getResource("praktikum4/data.txt").getFile()); fileReader = new FileReader(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum4/data.txt")).getFile());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); logger.throwing("KlausurenServer", "load", e.getCause());
} }
try (BufferedReader br = new BufferedReader(Objects.requireNonNull(fileReader))) { try (BufferedReader br = new BufferedReader(Objects.requireNonNull(fileReader))) {
for (String line = br.readLine(); line != null; line = br.readLine()) { for (String line = br.readLine(); line != null; line = br.readLine()) {
@ -131,15 +137,15 @@ public class KlausurenServer {
data.put(array[0], set); data.put(array[0], set);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.throwing("KlausurenServer", "load", e.getCause());
} }
} }
synchronized void save() { private synchronized void save() {
FileOutputStream fileOutputStream; FileOutputStream fileOutputStream;
PrintWriter printWriter = null; PrintWriter printWriter = null;
try { try {
fileOutputStream = new FileOutputStream(getClass().getClassLoader().getResource("praktikum4/data.txt").getFile()); fileOutputStream = new FileOutputStream(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum4/data.txt")).getFile());
printWriter = new PrintWriter(fileOutputStream); printWriter = new PrintWriter(fileOutputStream);
for (Map.Entry<String, TreeSet<Integer>> entry : data.entrySet()) { for (Map.Entry<String, TreeSet<Integer>> entry : data.entrySet()) {
@ -151,7 +157,7 @@ public class KlausurenServer {
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.throwing("KlausurenServer", "save", e.getCause());
} finally { } finally {
assert printWriter != null; assert printWriter != null;
printWriter.close(); printWriter.close();