Bibliothek.java
import keb.*;
public class Bibliothek extends EinAusRahmen {
BibliotheksDBsys dieBibliothek = new BibliotheksDBsys(this);
public static void main(String[] args) {
System.out.println("Hier ist das Bibliothekssystem.");
Anfang(new Bibliothek(),"Bibliothek",15,1);
}
class command {
String commandstring;
command(String u) {
commandstring = u;
}
void go() {
}
void go(String dieEingabe) {
}
}
//Definition eines Arrays von Objekten der Klasse command mit sofortiger
//Initialisierung.
//Jede Instanz implementiert die Methode go() auf andere Weise.
command[] thecommands = {
new command("Ende") {
void go(String e) {
Ende();
}
},
new command("DruckeDB") {
void go(String e) {
dieBibliothek.druckeAlle();
}
},
new command("NeuerAusleiher") {
void go(String e) {
if(WortAnz(e,1) < 3) {
zeigeAus("Falsche Zahl von Parametern für Kommando "+commandstring+
"\nBenötigt: NeuerAusleiher Vorname Nachname");
}
else {
dieBibliothek.neuerAusleiher(Wort(e,1,3),Wort(e,1,2));
}
}
},
new command("NeuesBuch") {
void go(String e) {
if(WortAnz(e,1) < 4) {
zeigeAus("Falsche Zahl von Parametern für Kommando "+commandstring+
"\nBenötigt: NeuesBuch Titel Vorname Nachname");
}
else {
dieBibliothek.neuesBuch(Wort(e,1,2),Wort(e,1,4),Wort(e,1,3));
}
}
},
Bibliothek.java
new command("NeuerStudent") {
void go(String e) {
if(WortAnz(e,1) < 3) {
zeigeAus("Falsche Zahl von Parametern für Kommando "+commandstring+
"\nBenötigt: NeuerStudent Vorname Nachname");
}
else {
dieBibliothek.neuerStudent(Wort(e,1,3),Wort(e,1,2));
}
}
},
new command("NeuerAngestellter") {
void go(String e) {
if(WortAnz(e,1) < 3) {
zeigeAus("Falsche Zahl von Parametern für Kommando "+commandstring+
"\nBenötigt: NeuerAngestellter Vorname Nachname");
}
else {
dieBibliothek.neuerAngestellter(Wort(e,1,3),Wort(e,1,2));
}
}
},
new command("DruckeInfos") {
void go(String e) {
dieBibliothek.druckeInfos();
}
},
new command("BuchAusleihen") {
void go(String e) {
if(WortAnz(e,1) < 3) {
zeigeAus("Falsche Zahl von Parametern für Kommando "+commandstring+
"\nBenötigt: BuchAusleihen Buchnummer Ausleihernummer");
}
else {
dieBibliothek.buchAusleihen(liesInt(e,1,2),liesInt(e,1,3));
}
}
},
new command("SetzeDatum") {
void go(String e) {
if(WortAnz(e,1) < 2) {
zeigeAus("Falsche Zahl von Parametern für Kommando "+commandstring+
"\nBenötigt: SetzeDatum Datum");
}
else {
dieBibliothek.setzeDatum(Wort(e,1,2));
}
}
},
new command("BuchZurueckGeben") {
void go(String e) {
if(WortAnz(e,1) < 3) {
zeigeAus("Falsche Zahl von Parametern für Kommando "+commandstring+
"\nBenötigt: BuchZurueckGeben Buchnummer");
}
else {
dieBibliothek.buchZurueckGeben(liesInt(e,1,2));
}
}
},
};
Bibliothek.java
public void Hilfe() {
zeigeAus("Dies ist das Bibliothekssystem .... die Kommandos lauten:");
for(int i=0; i<thecommands.length; i++) {
zeigeAus(thecommands[i].commandstring);
}
}
public void Antwort(String Eingabe) {
int i;
boolean fertig;
if(SatzAnz(Eingabe) >= 1) {
if(WortAnz(Eingabe,1) >= 1) {
i = 0;
fertig = false;
while(!fertig) {
if(i >= thecommands.length) {
fertig = true;
}
else if(thecommands[i].commandstring.compareTo(Wort(Eingabe,1,1)) ==
0) {
thecommands[i].go(Eingabe);
fertig = true;
}
else {
i++;
}
}
if(i >= thecommands.length) {
zeigeAus("Kein Kommando: "+Wort(Eingabe,1,1));
}
}
else {
zeigeAus("Nicht genügend Eingabezeichen? "+Eingabe);
}
}
else {
zeigeAus("Leere Eingabe? "+Eingabe);
}
}
public void Ende() {
zeigeAus("Schluss jetzt ...");
super.Ende();
}
}