Änderungen 05.12.2023 um 14:36
This commit is contained in:
parent
3cbe2b7cb2
commit
6f46678393
25
src/DiningPhilosophers/Fork.java
Normal file
25
src/DiningPhilosophers/Fork.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean take(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
18
src/DiningPhilosophers/Philosopher.java
Normal file
18
src/DiningPhilosophers/Philosopher.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
22
src/DiningPhilosophers/Table.java
Normal file
22
src/DiningPhilosophers/Table.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
src/Praktikum03/helloworld/ErrorWriter.java
Normal file
9
src/Praktikum03/helloworld/ErrorWriter.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package Praktikum03.helloworld;
|
||||||
|
|
||||||
|
public class ErrorWriter implements IHelloWorldWriter{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeHelloWorld(){
|
||||||
|
System.err.println("Hello World");
|
||||||
|
}
|
||||||
|
}
|
7
src/Praktikum03/helloworld/Executor.java
Normal file
7
src/Praktikum03/helloworld/Executor.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package Praktikum03.helloworld;
|
||||||
|
|
||||||
|
public class Executor{
|
||||||
|
public static void printHelloWorld(IHelloWorldWriter writer1, IHelloWorldWriter writer2, boolean second){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
6
src/Praktikum03/helloworld/IHelloWorldWriter.java
Normal file
6
src/Praktikum03/helloworld/IHelloWorldWriter.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package Praktikum03.helloworld;
|
||||||
|
|
||||||
|
public interface IHelloWorldWriter {
|
||||||
|
|
||||||
|
void writeHelloWorld();
|
||||||
|
}
|
9
src/Praktikum03/helloworld/OutWriter.java
Normal file
9
src/Praktikum03/helloworld/OutWriter.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package Praktikum03.helloworld;
|
||||||
|
|
||||||
|
public class OutWriter implements IHelloWorldWriter{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeHelloWorld(){
|
||||||
|
System.out.println("Hello World");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user