Last active
July 16, 2019 06:37
-
-
Save jtuttas/0f2bb0d85ae3b1f3f0db to your computer and use it in GitHub Desktop.
Aufgabe 4
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 ObjTraining { | |
public ObjTraining() { | |
Fahrzeugmarke p1 = new Fahrzeugmarke(75.0); | |
Fahrzeugmarke p2 = new Fahrzeugmarke(55, 10000); | |
p1.setHersteller("Hersteller 1"); | |
p2.setHersteller("Hersteller 2"); | |
p1.setPreis(10.15); | |
p2.setPreis(20.00); | |
System.out.println ("p1="+p1); | |
System.out.println ("p2="+p2); | |
System.out.println ("Das Durchgeschnittsgewicht beträgt:"+this.averageWeight(p1, p2)); | |
} | |
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) { | |
this.preis = 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