Last active
July 16, 2019 06:43
-
-
Save jtuttas/9504cb1048ef76d1c8ca to your computer and use it in GitHub Desktop.
Aufgabe 5 (Dachgepäckträger)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dq.fiae12e; | |
public class Dachgepaecktraeger { | |
private Fahrrad f1,f2; | |
private final double gewicht=15.0; | |
public void applyFahrrad1(Fahrrad f1) { | |
this.f1 = f1; | |
} | |
public void applyFahrrad2(Fahrrad f1) { | |
this.f2 = f1; | |
} | |
public double getGewicht() { | |
double g=gewicht; | |
if (f1!=null) g+=f1.getGewicht(); | |
if (f2!=null) g+=f2.getGewicht(); | |
return g; | |
} | |
public void removeFahrrad1() { | |
f1=null; | |
} | |
public void removeFahrrad2() { | |
f2=null; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dq.fiae12e; | |
public class Kfz extends Fahrzeugmarke { | |
private Dachgepaecktraeger dachg; | |
public Kfz(double gewicht) { | |
super(gewicht); | |
// TODO Auto-generated constructor stub | |
} | |
public Kfz(double gewicht, long laufleistung) { | |
super(gewicht, laufleistung); | |
// TODO Auto-generated constructor stub | |
} | |
public void drive(int h, int dkm) { | |
// TODO Auto-generated method stub | |
super.drive(h, dkm); | |
setPreis(getPreis()-0.3*h*dkm); | |
} | |
public void apply(Dachgepaecktraeger d) { | |
this.dachg=d; | |
} | |
@Override | |
public double getGewicht() { | |
// TODO Auto-generated method stub | |
//if (dachg!=null) return super.getGewicht()+dachg.getGewicht(); | |
//return super.getGewicht(); | |
return (dachg!=null?super.getGewicht()+dachg.getGewicht():super.getGewicht()); | |
} | |
public void drive(int km) { | |
// TODO Auto-generated method stub | |
super.drive(km); | |
setPreis(getPreis()-0.3*km); | |
} | |
@Override | |
public String toString() { | |
// TODO Auto-generated method stub | |
return "Ich bin ein KFZ:"+super.toString(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dq.fiae12e; | |
public class ObjTraining { | |
public ObjTraining() { | |
Fahrrad f1 = new Fahrrad(12, 0); | |
f1.setHersteller("Gudereit"); | |
f1.setPreis(600); | |
Fahrrad f2 = new Fahrrad(13.5, 0); | |
f2.setHersteller("Kettler"); | |
f2.setPreis(250); | |
Kfz kfz1 = new Kfz(800); | |
kfz1.setHersteller("Opel"); | |
kfz1.setPreis(15000); | |
Kfz kfz2 = new Kfz(950); | |
kfz2.setHersteller("Ford"); | |
kfz2.setPreis(6900); | |
f1.drive(122); | |
f2.drive(30, 22); | |
kfz1.drive(10000); | |
kfz2.drive(55000); | |
System.out.println ("f1="+f1); | |
System.out.println ("f2="+f2); | |
System.out.println ("kfz1="+kfz1); | |
System.out.println ("kfz2="+kfz2); | |
Dachgepaecktraeger da1= new Dachgepaecktraeger(); | |
kfz1.apply(da1); | |
da1.applyFahrrad1(f1); | |
da1.applyFahrrad2(f2); | |
System.out.println ("Mit Dachgepäcktrager kfz1="+kfz1); | |
} | |
private double averageWeight(Fahrzeug f1,Fahrzeug f2) { | |
return (f1.getGewicht()+f2.getGewicht())/2; | |
} | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
ObjTraining o = new ObjTraining(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment