Hey
Das folgende Szenario ist in BlueJ zu implementieren:
Hugo fährt mit seinem Golf von
Konstanz nach Radolfzell um dort seinen Freund Hans abzuholen. Anschliessend fahren die
beiden weiter nach München und steigen dort aus dem Auto aus.
Bisher habe ich diesen Quelltext:
Jetzt ist allerdings noch folgendes gefragt:
Die Klasse Szenario beinhaltet lediglich die Methode createScenario(), in der das oben genannte
Szenario mit instantiierten Objekten nachgestellt werden soll. Dies konnte beispielsweise
so aussehen:
//erstelle Szenario
...
...
//spiele Szenario nach
...
Insbesondere mit dem
oder
kann ich gar nichts anfangen. Was kann ich damit machen und wie kann ich die Aufgabe damit lösen?
Danke im Vorraus
Mfg
Das folgende Szenario ist in BlueJ zu implementieren:
Hugo fährt mit seinem Golf von
Konstanz nach Radolfzell um dort seinen Freund Hans abzuholen. Anschliessend fahren die
beiden weiter nach München und steigen dort aus dem Auto aus.
Java:

Bisher habe ich diesen Quelltext:
Java:
public class Car {
private String type;
private Person driver;
private Person codriver;
private Location location;
public Car(Location location) {
this.location = location;
} //Location
public void setType(String type) {
this.type = type;
}
public void driveTo(Location location) {
if (driver == null) {
System.out.println("Kein Fahrer im Auto");
}
else {this.location = location;
driver.setLocation(location);
if (codriver != null) {
codriver.setLocation(location);}
}
}
public void getOnAsDriver(Person driver) {
if (this.driver != null) {
System.out.println("Fahrersitz schon besetzt");
} else {
if (driver.location == location) {
this.driver = driver;}
else System.out.println("Auto und Person nicht am selben Ort"); }
}
public void getOnAsCoDriver(Person codriver) {
if (this.codriver != null) {
System.out.println("Beifahrersitz schon besetzt");
} else {
this.codriver = codriver;
}
}
public void getOffDriver(Person driver) {
this.driver = null;
}
public void getOffCoDriver(Person codriver) {
this.codriver = null;
}
}
public class Person {
String name;
public Location location;
public Person(String name) {
this.name = name;
}
public void setLocation(Location location) {
this.location = location; }
}
public class Location {
private String name;
public Location(String name) {
this.name = name;
}
}
Jetzt ist allerdings noch folgendes gefragt:
Die Klasse Szenario beinhaltet lediglich die Methode createScenario(), in der das oben genannte
Szenario mit instantiierten Objekten nachgestellt werden soll. Dies konnte beispielsweise
so aussehen:
//erstelle Szenario
Java:
Location radolfzell = new Location(...);
Java:
Car golf = new Car(...);
//spiele Szenario nach
Java:
golf.driveTo(radolfzell);
Insbesondere mit dem
Java:
Car golf = new Car(...);
Java:
Location radolfzell = new Location(...);
Danke im Vorraus
Mfg
Zuletzt bearbeitet: