device transfer

main
2wenty1ne 2024-10-09 22:26:00 +02:00
commit 085ebeb470
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,32 @@
public class Sensor extends Thread {
private final long frequency;
public Sensor(long frequency) {
this.frequency = frequency;
start();
}
public long getFrequency() {
return this.frequency;
}
protected String reading() {
// eigentlich abstract
return null;
}
@Override
public void run() {
while(true) {
System.out.println("reading: " + reading());
try {
Thread.sleep(this.frequency);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
public static void main(String... args) {
var s = new Sensor(1000);
}
}

View File

@ -0,0 +1,21 @@
import javax.swing.plaf.TableHeaderUI;
import java.util.Random;
public class Thermometer extends Sensor {
private final Random rand;
public Thermometer(long frequency) {
super(frequency);
this.rand = new Random();
}
@Override
protected String reading() {
return String.format("(%04d freq.): %3d°C", getFrequency(), this.rand.nextInt(100));
}
public static void main(String[] args) {
var s1 = new Thermometer(1000);
var s2 = new Thermometer(3000);
}
}