Adding autos
This commit is contained in:
parent
7b7b96238f
commit
ff367a664b
40
Gabriel-Java-Learning/src/com/p4ddy/java_tutorial/Auto.java
Normal file
40
Gabriel-Java-Learning/src/com/p4ddy/java_tutorial/Auto.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package com.p4ddy.java_tutorial;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Auto {
|
||||
public String hersteller;
|
||||
public int leistung;
|
||||
public String farbe;
|
||||
public int tueren;
|
||||
public List<Rad> raeder;
|
||||
|
||||
public Auto(String hersteller, int leistung, String farbe, int tueren) {
|
||||
this.hersteller = hersteller;
|
||||
this.leistung = leistung;
|
||||
this.farbe = farbe;
|
||||
this.tueren = tueren;
|
||||
|
||||
this.raeder = new ArrayList<>();
|
||||
Rad rad1 = new Rad();
|
||||
Rad rad2 = new Rad();
|
||||
Rad rad3 = new Rad();
|
||||
Rad rad4 = new Rad();
|
||||
|
||||
this.raeder.add(rad1);
|
||||
this.raeder.add(rad2);
|
||||
this.raeder.add(rad3);
|
||||
this.raeder.add(rad4);
|
||||
}
|
||||
|
||||
public void fahren(){
|
||||
System.out.println("Auto fährt!");
|
||||
|
||||
int neueProfiltiefe = this.raeder.get(0).fahren();
|
||||
this.raeder.get(1).fahren();
|
||||
this.raeder.get(2).fahren();
|
||||
|
||||
System.out.println("Neue Profiltiefe: " + neueProfiltiefe);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,14 @@ package com.p4ddy.java_tutorial;
|
|||
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args){
|
||||
System.out.println("Hello World!");
|
||||
Auto auto1 = new Auto("Tesla", 500, "Rot", 5);
|
||||
Auto auto2 = new Auto("Porsche", 1000, "Gelb", 3);
|
||||
|
||||
System.out.println("Auto soll fahren");
|
||||
auto1.fahren();
|
||||
auto1.fahren();
|
||||
|
||||
auto1.raeder.forEach(rad -> System.out.print(rad.getProfiltiefe() + " "));
|
||||
System.out.println(auto2.hersteller);
|
||||
}
|
||||
}
|
||||
|
|
18
Gabriel-Java-Learning/src/com/p4ddy/java_tutorial/Rad.java
Normal file
18
Gabriel-Java-Learning/src/com/p4ddy/java_tutorial/Rad.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package com.p4ddy.java_tutorial;
|
||||
|
||||
public class Rad {
|
||||
private int profiltiefe;
|
||||
|
||||
public Rad() {
|
||||
this.profiltiefe = 10;
|
||||
}
|
||||
|
||||
public int fahren(){
|
||||
this.profiltiefe = this.profiltiefe - 1;
|
||||
return this.profiltiefe;
|
||||
}
|
||||
|
||||
public int getProfiltiefe(){
|
||||
return profiltiefe;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user