added Aufgabenblatt 10

This commit is contained in:
Sven Vogel 2023-05-25 14:31:21 +02:00
parent 603a8db49f
commit 65be95e3ca
17 changed files with 671 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ADDITIONAL_TAGS" value="post" />
</inspection_tool>
</profile>
</component>

View File

@ -2,6 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/AufgabenBlatt10/AufgabenBlatt10.iml" filepath="$PROJECT_DIR$/AufgabenBlatt10/AufgabenBlatt10.iml" />
<module fileurl="file://$PROJECT_DIR$/AufgabenBlatt3/AufgabenBlatt3.iml" filepath="$PROJECT_DIR$/AufgabenBlatt3/AufgabenBlatt3.iml" /> <module fileurl="file://$PROJECT_DIR$/AufgabenBlatt3/AufgabenBlatt3.iml" filepath="$PROJECT_DIR$/AufgabenBlatt3/AufgabenBlatt3.iml" />
<module fileurl="file://$PROJECT_DIR$/AufgabenBlatt4/AufgabenBlatt4.iml" filepath="$PROJECT_DIR$/AufgabenBlatt4/AufgabenBlatt4.iml" /> <module fileurl="file://$PROJECT_DIR$/AufgabenBlatt4/AufgabenBlatt4.iml" filepath="$PROJECT_DIR$/AufgabenBlatt4/AufgabenBlatt4.iml" />
<module fileurl="file://$PROJECT_DIR$/AufgabenBlatt6/AufgabenBlatt6.iml" filepath="$PROJECT_DIR$/AufgabenBlatt6/AufgabenBlatt6.iml" /> <module fileurl="file://$PROJECT_DIR$/AufgabenBlatt6/AufgabenBlatt6.iml" filepath="$PROJECT_DIR$/AufgabenBlatt6/AufgabenBlatt6.iml" />

29
AufgabenBlatt10/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-19" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -0,0 +1,54 @@
package aufgabe4;
import javax.annotation.processing.Generated;
/**
* Generic test class defining an abstract dog
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
@SuppressWarnings("unused")
public class Hund {
/**
* name of the dog
*/
protected String name;
@Generated({})
public Hund(String name) {
this.name = name;
}
/**
* Prints the barking noises this dog makes to System.out.
*/
public void bellen() {
System.out.println("not so abstract dog barking: wau wau wuff wuff wauf");
}
@Generated({})
public String getName() {
return name;
}
/**
* @return a short description marking this instance as abstract and the name
*/
@Override
public String toString() {
return "I am an cosmically abstract transmon dog existing only in the quantum realm of the heap and my name is " + name;
}
}

View File

@ -0,0 +1,31 @@
package aufgabe4;
/**
* Generic test class for testing the dogs ;)
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Main {
public static void main(String[] args) {
Hund rocky = new Hund("Rocky");
Hund sissi = new Schosshund("Sissi");
Hund hektor = new Wachhund("Hektor");
rocky.bellen();
sissi.bellen();
hektor.bellen();
}
}

View File

@ -0,0 +1,47 @@
package aufgabe4;
import javax.annotation.processing.Generated;
import java.lang.annotation.Inherited;
/**
* Generic test class implementing a cute doggo based on an abstract dog
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
@SuppressWarnings("unused")
public class Schosshund extends Hund {
@Generated({})
public Schosshund(String name) {
super(name);
}
/**
* Prints the barking noises this dog makes to System.out as:
* wau wau wau wau
*/
@Override
public void bellen() {
System.out.println("wau wau wau wau");
}
/**
* @return the race of the dog ("Schosshund") and the name as string
*/
@Override
public String toString() {
return "I am a Schosshund and my name is " + name;
}
}

View File

@ -0,0 +1,46 @@
package aufgabe4;
import javax.annotation.processing.Generated;
/**
* Generic test class implementing a watchdog based on an abstract dog
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
@SuppressWarnings("unused")
public class Wachhund extends Hund {
@Generated({})
public Wachhund(String name) {
super(name);
}
/**
* Prints the barking noises this dog makes to System.out as:
* WUFF WUFF WUFF WUFF WUFF WUFF WUFF WUFF WUFF WUFF
*/
@Override
public void bellen() {
System.out.println("WUFF WUFF WUFF WUFF WUFF WUFF WUFF WUFF WUFF WUFF");
}
/**
* @return the race of the dog ("Wachhund") and the name as string
*/
@Override
public String toString() {
return "I am a Wachhund and my name is " + name;
}
}

View File

@ -0,0 +1,40 @@
package aufgabe5;
/**
* Generic test class defining an elephant
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Elephant extends Tier {
public Elephant() {
super(4, "elephanten grau");
}
/**
* Trumpet for a certain amount of duration through which sth. is printed to System.out.
* The precision of timing is up to milliseconds.
* @param dauer duration to trumpet in seconds
*/
public void trompeten(double dauer) {
var start = System.currentTimeMillis();
// convert dauer from seconds to milliseconds
var duration = (int) (dauer * 1e3);
while(System.currentTimeMillis() - start < duration) {
System.out.println("törööööööööööööö");
}
}
}

View File

@ -0,0 +1,62 @@
package aufgabe5;
/**
* Generic test class defining a cage for animals
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
@SuppressWarnings("unused")
public class Gehege {
/**
* How many animals fit in the cage
*/
private int kapazitaet;
/**
* Size of the cage in square meters
*/
private final double groesse;
public Gehege(int kapazitaet, double groesse) {
this.kapazitaet = kapazitaet;
this.groesse = groesse;
}
/**
* Add a new animal to the cage.
* @post increments capacity
* @param animal the animal to add
*/
public void addTier(Tier animal) {
System.out.println("added animal " + animal);
}
/**
* Remove an animal to the cage.
* @post decrements capacity
* @param animal the animal to remove
*/
public void removeTier(Tier animal) {
System.out.println("removed animal " + animal);
}
/**
* Feeds the animals of this cage.
* Does effectively nothing.
*/
public void tiereFuettern() {
// feed the animals in some way cuz we don't know the exact animals in the cage
System.out.println("feeded animals");
}
}

View File

@ -0,0 +1,41 @@
package aufgabe5;
/**
* Generic test class defining a centipede
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class Tausendfuessler extends Tier {
public Tausendfuessler(String farbe) {
super(1000, farbe);
}
/**
* Does effectively nothing.
*/
public void beineEntheddern() {
// do sth.
System.out.println("Beinchen entheddert");
}
/**
* Does effectively nothing.
*/
public void beineVerheddern() {
// do sth.
System.out.println("Beinchen verheddert");
}
}

View File

@ -0,0 +1,45 @@
package aufgabe5;
import org.junit.Test;
/**
* Generic test class for testing animals
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class TestAnimals {
@Test
public void test() {
var tier = new Tier(99, "blut rot");
var tausendsasser = new Tausendfuessler("tausend füssler schwarz");
var elefranz = new Elephant();
var schlachtHof = new Gehege(5, 0.5);
schlachtHof.addTier(tier);
schlachtHof.addTier(tausendsasser);
schlachtHof.addTier(elefranz);
schlachtHof.removeTier(tausendsasser);
tausendsasser.beineEntheddern();
tausendsasser.beineVerheddern();
elefranz.trompeten(4.0);
tier.fressen();
tier.laufen(4300_000);
}
}

View File

@ -0,0 +1,48 @@
package aufgabe5;
/**
* Generic test class defining an animal
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
@SuppressWarnings("unused")
public class Tier {
private final int anzahlBeine;
private final String farbe;
public Tier(int anzahlBeine, String farbe) {
this.anzahlBeine = anzahlBeine;
this.farbe = farbe;
}
/**
* Walk a certain distance.
* Does effectively nothing.
* @param strecke the distance to walk
*/
public void laufen(double strecke) {
// walk the distance
System.out.println(strecke + "m gelaufen");
}
/**
* Eat sth.
* Does effectively nothing.
*/
public void fressen() {
// eat sth.
System.out.println("yum yum yum yum yum yum yum yum");
}
}

View File

@ -0,0 +1,37 @@
package aufgabe6;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Generic test class for testing airplanes
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
public class AirplaneTest {
@Test
public void test() {
var plane1 = new Verkehrsflugzeug("boeing", 870, "q0tb47q6t3478t6q78", 220);
var plane2 = plane1;
var plane3 = new Doppeldecker("airbus", 170, "ß0q784tß089q34t", false);
assertEquals(plane1, plane2);
System.out.println("Can loop? " + plane3.getLooping());
}
}

View File

@ -0,0 +1,66 @@
package aufgabe6;
/**
* Generic test class defining a double winged airplane
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
@SuppressWarnings("unused")
public final class Doppeldecker extends Flugzeug {
/**
* Minimum speed to fly a looping in km/s
*/
public static final double LOOPING_SPEED = 320;
private final boolean offenesCockpit;
public Doppeldecker(String hersteller, int maxSpeed, String immatrikulationNumber, boolean offenesCockpit) {
super(hersteller, maxSpeed, 2);
setImmatNummer(immatrikulationNumber);
this.offenesCockpit = offenesCockpit;
}
public Doppeldecker(String hersteller, int maxSpeed, String immatrikulationNumber) {
super(hersteller, maxSpeed, 2);
setImmatNummer(immatrikulationNumber);
this.offenesCockpit = true;
}
/**
* whether the plane as an open cockpit
* @return whether the plane as an open cockpit
*/
public boolean isOffenesCockpit() {
return offenesCockpit;
}
/**
* @return if this plane can fly a looping
*/
@Override
public boolean getLooping() {
return getMaxSpeed() > LOOPING_SPEED;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Doppeldecker plane) {
return super.equals(obj) && plane.offenesCockpit == this.offenesCockpit;
}
return false;
}
}

View File

@ -0,0 +1,32 @@
package aufgabe6;
abstract class Flugzeug {
private String hersteller;// Herstellername
private int maxSpeed; // Max. Geschwindigkeit
private String immatNummer; // Immatrikulationsnummer
private int anzahlFluegel = 1; // Anzahl Flügelpaare
public Flugzeug(String hersteller, int maxSpeed, int anzahlFluegel) {
this.hersteller = hersteller;
this.maxSpeed = maxSpeed;
this.anzahlFluegel = anzahlFluegel;
}
public String getImmatNummer() {
return immatNummer;
}
protected void setImmatNummer(String immatNummer) {
this.immatNummer = immatNummer;
}
public int getMaxSpeed() {
return maxSpeed;
}
abstract public boolean getLooping();
@Override
public boolean equals(Object obj) {
if (obj instanceof Verkehrsflugzeug plane) {
return this.immatNummer.equals(plane.getImmatNummer()) && this.maxSpeed == plane.getMaxSpeed();
}
return false;
}
}

View File

@ -0,0 +1,63 @@
package aufgabe6;
/**
* Generic test class defining a passenger airplane
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
@SuppressWarnings("unused")
public class Verkehrsflugzeug extends Flugzeug {
private int passangers;
public Verkehrsflugzeug(String hersteller, int maxSpeed, String immatrikulationNumber, int passangers) {
super(hersteller, maxSpeed, 1);
this.passangers = passangers;
this.setImmatNummer(immatrikulationNumber);
}
/**
* @return the number of passengers
*/
public int getAnzahlPassagiere() {
return passangers;
}
/**
* Set the number of passengers
* @post alters the amount of passengers
* @param passengers the new amount of passengers
*/
public void setPassangers(int passengers) {
this.passangers = passengers;
}
/**
* @return if this plane can fly a looping
*/
@Override
public final boolean getLooping() {
return false;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Verkehrsflugzeug plane) {
return super.equals(obj) && plane.getAnzahlPassagiere() == this.passangers;
}
return false;
}
}