Last active
July 16, 2019 06:40
-
-
Save jtuttas/1a0dfd2bee1149f8bc9e to your computer and use it in GitHub Desktop.
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
public class Fahrzeug { | |
private double gewicht; | |
private long laufleistung; | |
public Fahrzeug (double gewicht) { | |
this.gewicht=gewicht; | |
} | |
public Fahrzeug (double gewicht, long laufleistung) { | |
this.gewicht=gewicht; | |
this.laufleistung=laufleistung; | |
} | |
public double getGewicht() { | |
return gewicht; | |
} | |
public void drive(int km) { | |
laufleistung+=km; | |
} | |
public void drive(int h,int dkm) { | |
laufleistung+=h*dkm; | |
} | |
public void setGewicht(double gewicht) { | |
this.gewicht = gewicht; | |
} | |
public long getLaufleistung() { | |
return laufleistung; | |
} | |
public String toString() { | |
// TODO Auto-generated method stub | |
return "Laufleistung="+getLaufleistung()+" Gewicht="+getGewicht(); | |
} | |
} |
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
public class Fahrrad extends Fahrzeugmarke { | |
public Fahrrad(double gewicht, long laufleistung) { | |
super(gewicht, laufleistung); | |
// TODO Auto-generated constructor stub | |
} | |
@Override | |
public String toString() { | |
// TODO Auto-generated method stub | |
return "Ich bin ein Fahrrad:"+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
public class Kfz extends Fahrzeugmarke { | |
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 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
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); | |
} | |
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(); | |
} | |
} |
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
public class Fahrzeugmarke extends Fahrzeug { | |
private double preis; | |
private String hersteller; | |
public Fahrzeugmarke(double gewicht) { | |
super(gewicht); | |
// TODO Auto-generated constructor stub | |
} | |
public Fahrzeugmarke(double gewicht, long laufleistung) { | |
super(gewicht, laufleistung); | |
// TODO Auto-generated constructor stub | |
} | |
public double getPreis() { | |
return preis; | |
} | |
public void setPreis(double preis) { | |
/** | |
* Lange Form | |
*/ | |
/* | |
if (preis<=0) { | |
this.preis=0; | |
} | |
else { | |
this.preis = preis; | |
} | |
*/ | |
this.preis=(preis<=0.0 ? 0 : preis); | |
} | |
public String getHersteller() { | |
return hersteller; | |
} | |
public void setHersteller(String hersteller) { | |
this.hersteller = hersteller; | |
} | |
public String toString() { | |
// TODO Auto-generated method stub | |
return "Name="+hersteller+" Preis="+preis+" "+super.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment