Also ich habe in meinem Buch die Aufgabe bekommen ein Programm zu schreiben welches einen Flug simuliert. Jetzt wollte ich fragen, ob der Code "sauber" programmiert worden ist, und ob er auch richtig ist bzw. was ich daran ändern könnte.
Die Flugzeugklasse:
Die Koord Klasse:
Die Wasserturm Klasse:
Die Simulator Klasse:
Die Flugzeugklasse:
Java:
package Flugsimulator;
class Flugzeug {
String typ;
int turbinen;
int spannWeite;
int maxGeschw;
Koord position;
int höhe;
int aktuelleGeschw;
Flugzeug(int maxGeschw){
this.maxGeschw = maxGeschw;
position = new Koord(0,0);
höhe = 0;
aktuelleGeschw = 0;
}
void abheben(int flugHöhe){
if(flugHöhe > 60){
System.out.println("Bitte wählen Sie eine Höhe unter 60!");
}
else{
System.out.println("Ihr Flugzeug ist erfolgreich abgehoben!");
}
}
void fliegen(int x_koord, int y_koord){
if(x_koord == 70 &&
y_koord == 30 ||
x_koord == 50 &&
y_koord == 90 ||
x_koord == 45 &&
y_koord == 10){
System.out.println("Ihr Flugzeug ist in einer der drei Wassertürme geflogen!");
}
else
System.out.println("Ihr Flugzeug fliegt!");
}
}
Die Koord Klasse:
Java:
package Flugsimulator;
class Koord{
int x;
int y;
Koord(int x, int y){
this.x = x;
this.y = y;
}
}
Java:
package Flugsimulator;
class Wasserturm {
Koord position;
int breite;
int höhe;
int tiefe;
Wasserturm(Koord pos, int b, int h, int t){
this.position = pos;
this.breite = b;
this.höhe = h;
this.tiefe = t;
}
}
Java:
package Flugsimulator;
public class Simulator {
public static void main(String[] args){
Flugzeug flugezeug1 = new Flugzeug(300);
Wasserturm turm1 = new Wasserturm(new Koord(70,30), 30, 60, 15);
Wasserturm turm2 = new Wasserturm(new Koord(50,90), 15, 60, 30);
Wasserturm turm3 = new Wasserturm(new Koord(45,10), 50, 17, 56);
flugezeug1.abheben(50);
flugezeug1.fliegen(45, 10);
}
}