1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
|
import java.util.ArrayList;
import java.util.Scanner;
public class Aufzug extends Thread{
static ArrayList<Integer> stationen = new ArrayList<Integer>();
public void naechsteStation(){
try {
this.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(stationen.get(0));
stationen.remove(0);
}
public void eintragStation(){
Scanner sc = new Scanner(System.in);
System.out.println("Bitte geben Sie eine Station ein");
int station= Integer.parseInt(sc.next());
stationen.add(station);
//sc.close();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Aufzug a = new Aufzug();
Thread regulär = new Thread(a){ public void run(){ for (int i=0; i<10; i++) a.naechsteStation();}};
Thread eintrag = new Thread(a){ public void run(){ for (int i=0; i<10; i++) a.eintragStation();}};
stationen.add(1);
stationen.add(3);
stationen.add(5);
regulär.start();
eintrag.start();
}
}
|