Löschung von unnötigen Dateien 19.12.2023 um 16.13
This commit is contained in:
parent
49b307b680
commit
7fef449863
@ -1,36 +0,0 @@
|
|||||||
package Prog3.src.DiningPhilosophers;
|
|
||||||
|
|
||||||
public class Fork {
|
|
||||||
|
|
||||||
private boolean inUse = false;
|
|
||||||
private final int id;
|
|
||||||
|
|
||||||
public Fork(int id){
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId(){
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean take(){
|
|
||||||
synchronized (this){
|
|
||||||
if (inUse){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
inUse = true;
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}catch (InterruptedException e){
|
|
||||||
System.out.println("Gabel mit ID: " + id + " hat nicht funktioniert");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(){
|
|
||||||
synchronized(this){
|
|
||||||
inUse = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package Prog3.src.DiningPhilosophers;
|
|
||||||
|
|
||||||
public class Philosopher implements Runnable{
|
|
||||||
protected int id;
|
|
||||||
protected final Fork left;
|
|
||||||
protected final Fork right;
|
|
||||||
|
|
||||||
public Philosopher(int id, Fork left, Fork right) {
|
|
||||||
this.id = id;
|
|
||||||
this.left = left;
|
|
||||||
this.right = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(){
|
|
||||||
while(true) {
|
|
||||||
allocateForks();
|
|
||||||
System.out.println("Philosopher " + id + " is eating");
|
|
||||||
try{
|
|
||||||
Thread.sleep(2000);
|
|
||||||
}catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
left.put();
|
|
||||||
right.put();
|
|
||||||
System.out.println("Philosopher " + id + " finished eating");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void allocateForks() {
|
|
||||||
Fork firstFork, secondFork;
|
|
||||||
|
|
||||||
if (left.getId() < right.getId()){
|
|
||||||
firstFork = left;
|
|
||||||
secondFork = right;
|
|
||||||
} else {
|
|
||||||
firstFork = right;
|
|
||||||
secondFork = left;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Philosopher " + id + " is trying to take Fork " + firstFork.getId());
|
|
||||||
while (!firstFork.take())
|
|
||||||
Thread.yield();
|
|
||||||
System.out.println("Philosopher " + id + " got Fork " + firstFork.getId());
|
|
||||||
System.out.println("Philosopher " + id + " is trying to take Fork " + secondFork.getId());
|
|
||||||
while (!secondFork.take())
|
|
||||||
Thread.yield();
|
|
||||||
System.out.println("Philosopher " + id + " got Fork " + secondFork.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package Prog3.src.DiningPhilosophers;
|
|
||||||
|
|
||||||
public class Table {
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
Fork[] forks = { new Fork(0), new Fork(1), new Fork(2),
|
|
||||||
new Fork(3), new Fork(4)};
|
|
||||||
|
|
||||||
Philosopher[] philosophers = {
|
|
||||||
new Philosopher(0, forks[0], forks[1]),
|
|
||||||
new Philosopher(1, forks[1], forks[2]),
|
|
||||||
new Philosopher(2, forks[2], forks[3]),
|
|
||||||
new Philosopher(3, forks[3], forks[4]),
|
|
||||||
new Philosopher(4, forks[4], forks[0])
|
|
||||||
};
|
|
||||||
|
|
||||||
for (Philosopher philosopher : philosophers) {
|
|
||||||
|
|
||||||
Thread t = new Thread(philosopher);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package DistributedSorter;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class SorterClient implements Runnable{
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SorterClient client = new SorterClient();
|
|
||||||
client.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendLine(Socket socket, String line) throws IOException {
|
|
||||||
OutputStream out = socket.getOutputStream();
|
|
||||||
PrintWriter writer = new PrintWriter(out);
|
|
||||||
writer.println(line);
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String receiveLine(Socket socket) throws IOException {
|
|
||||||
InputStream in = socket.getInputStream();
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
|
||||||
return reader.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine();
|
|
||||||
if(line.isEmpty())
|
|
||||||
break;
|
|
||||||
line = sort(line);
|
|
||||||
System.out.println(line);
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String sort(String line) {
|
|
||||||
try (Socket socket = new Socket("localhost", 12345)) {
|
|
||||||
|
|
||||||
sendLine(socket, line);
|
|
||||||
return receiveLine(socket);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "Error connecting to the server.";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package DistributedSorter;
|
|
||||||
|
|
||||||
import jdk.jshell.spi.ExecutionControl;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class SorterServer implements Runnable {
|
|
||||||
|
|
||||||
Socket client;
|
|
||||||
public SorterServer(Socket client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
final int port = 12345;
|
|
||||||
try (ServerSocket socket = new ServerSocket(port)) {
|
|
||||||
|
|
||||||
while (true){
|
|
||||||
Socket client = socket.accept();
|
|
||||||
Thread thread = new Thread(new SorterServer(client));
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.err.println("Error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendLine(Socket socket, String line) throws IOException {
|
|
||||||
OutputStream out = socket.getOutputStream();
|
|
||||||
PrintWriter writer = new PrintWriter(out);
|
|
||||||
writer.println(line);
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String receiveLine(Socket socket) throws IOException {
|
|
||||||
InputStream in = socket.getInputStream();
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
|
||||||
return reader.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private String sort(String line){
|
|
||||||
char[] chars = line.toCharArray();
|
|
||||||
Arrays.sort(chars);
|
|
||||||
return new String(chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try{
|
|
||||||
String line = receiveLine(client);
|
|
||||||
String answer = sort(line);
|
|
||||||
sendLine(client, answer);
|
|
||||||
System.out.println(line + "-->"+ answer);
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("Fehler");
|
|
||||||
}
|
|
||||||
finally{
|
|
||||||
try{client.close();} catch(Exception e)
|
|
||||||
{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
package Praktikum01;
|
|
||||||
|
|
||||||
|
|
||||||
public class Zahlenfilter {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int upper_limit = 200;
|
|
||||||
if (args.length > 0){
|
|
||||||
upper_limit = Integer.parseInt(args[0]);
|
|
||||||
}else{
|
|
||||||
System.out.println("Keine Zahl eingegeben. Es wird mit 200 weitergearbeitet.");
|
|
||||||
}
|
|
||||||
int count = 1;
|
|
||||||
Zahlenfilter z = new Zahlenfilter(upper_limit);
|
|
||||||
z.run(count);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
private Zahlenfilter(int limit){
|
|
||||||
|
|
||||||
this.limit = limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void run(int c){
|
|
||||||
for(int i = 0; i < this.limit; i++){
|
|
||||||
int preC = c-1;
|
|
||||||
int ergebnis = c + preC;
|
|
||||||
int ergebnis2 = preC + c;
|
|
||||||
|
|
||||||
if (c % 5 == 0){
|
|
||||||
System.out.println(c + " ist durch 5 teilbar");
|
|
||||||
c++;
|
|
||||||
}else if(c % 10 == 9){
|
|
||||||
System.out.println(c + " endet auf 9");
|
|
||||||
c++;
|
|
||||||
}else if(ergebnis % 3 == 0 && ergebnis2 % 3 == 0){
|
|
||||||
System.out.println(c + " und " + preC + " addiert ergeben " + ergebnis + " und " + ergebnis2 + " ist durch 3 teilbar." );
|
|
||||||
c++;
|
|
||||||
}else{
|
|
||||||
System.out.println(c);
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
package Praktikum03;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class TriangleChecker {
|
|
||||||
|
|
||||||
public enum TriangleType {
|
|
||||||
NONE,
|
|
||||||
NORMAL,
|
|
||||||
ISOSCELES, // Gleichschenklig
|
|
||||||
EQUILATERAL // Gleichseitig
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Scanner s = new Scanner(System.in);
|
|
||||||
System.out.println("Geben Sie die Seitenlängen ein.");
|
|
||||||
float a = enterFloat(s, "a: ");
|
|
||||||
float b = enterFloat(s, "b: ");
|
|
||||||
float c = enterFloat(s, "c: ");
|
|
||||||
s.close();
|
|
||||||
printAnalysis(a, b, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Eingabe einer Seitenlänge
|
|
||||||
private static float enterFloat(Scanner s, String prompt) {
|
|
||||||
System.out.print(prompt);
|
|
||||||
return s.nextFloat();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ausgabe der ermittelten Dreiecksart
|
|
||||||
private static void printAnalysis(float a, float b, float c) {
|
|
||||||
TriangleType type = checkTriangle(a, b, c);
|
|
||||||
switch (type) {
|
|
||||||
case NONE -> System.out.println("Kein Dreieck");
|
|
||||||
case NORMAL -> System.out.println("Dreieck");
|
|
||||||
case ISOSCELES -> System.out.println("Gleichschenkliges Dreieck");
|
|
||||||
case EQUILATERAL -> System.out.println("Gleichseitiges Dreieck");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Analyse der Dreiecksart
|
|
||||||
public static TriangleType checkTriangle(float a, float b, float c) {
|
|
||||||
|
|
||||||
|
|
||||||
if(a == b && b == c)
|
|
||||||
return TriangleType.EQUILATERAL;
|
|
||||||
if(a == b || b == c || a == c)
|
|
||||||
return TriangleType.ISOSCELES;
|
|
||||||
if(a + b < c || a + c < b || b + c < a)
|
|
||||||
return TriangleType.NONE;
|
|
||||||
if(a < 0 || b < 0 || c < 0)
|
|
||||||
return TriangleType.NONE;
|
|
||||||
|
|
||||||
return TriangleType.NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
package Praktikum03;
|
|
||||||
|
|
||||||
|
|
||||||
public class Zahlenfilter {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int upper_limit = 200;
|
|
||||||
if (args.length > 0)
|
|
||||||
upper_limit = Integer.parseInt(args[0]);
|
|
||||||
Zahlenfilter z = new Zahlenfilter(upper_limit);
|
|
||||||
z.printNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int boundary;
|
|
||||||
|
|
||||||
private Zahlenfilter(int limit){
|
|
||||||
boundary = limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printNumber(){
|
|
||||||
for(int i = 1; i <=boundary; i++){
|
|
||||||
if(filter(i))
|
|
||||||
System.out.println(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean filter(int i){
|
|
||||||
return !(checkDivisibleBy5(i) || checkEndsWith9(i) || checkSumDivisibleBy3(i, i-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkDivisibleBy5(int i) {
|
|
||||||
return(i % 5 == 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkEndsWith9(int i){
|
|
||||||
return(i % 10 == 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkSumDivisibleBy3(int i, int j){
|
|
||||||
return((i+j) % 3 == 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public class ErrorWriter implements IHelloWorldWriter{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeHelloWorld(){
|
|
||||||
System.err.println("Hello World");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public class Executor{
|
|
||||||
public static void printHelloWorld(IHelloWorldWriter writer1, IHelloWorldWriter writer2, boolean second){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public interface IHelloWorldWriter {
|
|
||||||
|
|
||||||
void writeHelloWorld();
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public class OutWriter implements IHelloWorldWriter{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeHelloWorld(){
|
|
||||||
System.out.println("Hello World");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package Prog3.src.Praktikum05;
|
package Praktikum05;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package Prog3.src.Praktikum05;
|
package Praktikum05;
|
||||||
|
|
||||||
public class EscapeBot extends Bot{
|
public class EscapeBot extends Bot{
|
||||||
protected EscapeBot(String args[]){
|
protected EscapeBot(String args[]){
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package Prog3.src.Praktikum05;
|
package Praktikum05;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user