Skip to content

Instantly share code, notes, and snippets.

@jtuttas
Created September 25, 2014 08:21
Show Gist options
  • Save jtuttas/96d64146ff5a26fdad06 to your computer and use it in GitHub Desktop.
Save jtuttas/96d64146ff5a26fdad06 to your computer and use it in GitHub Desktop.
Aufgabe 3.1
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();
}
}
public class ObjTraining {
public ObjTraining() {
Fahrzeug fa1 = new Fahrzeug(55);
Fahrzeug fa2 = new Fahrzeug(75,10000);
fa1.drive(300);
fa2.drive(2, 30);
fa1.drive(1,55);
System.out.println ("Fa1="+fa1);
System.out.println ("Fa2="+fa2);
System.out.println ("Das Durchgeschnittsgewicht beträgt:"+this.averageWeight(fa1, fa2));
}
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