Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:blc:informatik:ffprg1-2020:oop [2021/03/18 10:17] michael.greminger |
lehrkraefte:blc:informatik:ffprg1-2020:oop [2021/03/26 18:02] (current) michael.greminger |
||
---|---|---|---|
Line 4: | Line 4: | ||
=== Präsentation === | === Präsentation === | ||
+ | {{lehrkraefte: | ||
=== Aufgabe 1 === | === Aufgabe 1 === | ||
Line 18: | Line 19: | ||
<hidden Lösungsvorschlag> | <hidden Lösungsvorschlag> | ||
- | <code python | + | <code python> |
class Konto: | class Konto: | ||
def __init__(self, | def __init__(self, | ||
Line 33: | Line 34: | ||
k2 = Konto(" | k2 = Konto(" | ||
print k1.kontostand() | print k1.kontostand() | ||
- | print k2.inhaber() | + | print k2.inhaber() |
- | </ | + | </ |
</ | </ | ||
Line 50: | Line 51: | ||
<hidden Lösungsvorschlag> | <hidden Lösungsvorschlag> | ||
- | <code python | + | <code python> |
from datetime import datetime | from datetime import datetime | ||
Line 81: | Line 82: | ||
k2 = Konto(" | k2 = Konto(" | ||
print k1.kontostand() | print k1.kontostand() | ||
- | print k2.inhaber() | + | print k2.inhaber() |
</ | </ | ||
</ | </ | ||
Line 90: | Line 91: | ||
<hidden Lösungsvorschlag> | <hidden Lösungsvorschlag> | ||
- | <code python | + | <code python> |
from datetime import datetime | from datetime import datetime | ||
Line 105: | Line 106: | ||
return self._kontostand | return self._kontostand | ||
| | ||
- | def addBuchung(self, | + | def addBuchung(self, |
- | | + | |
- | self._buchungen.append(b) | + | self._buchungen.append(buchungInstanz) |
- | self._kontostand += b.betrag() | + | self._kontostand += buchungInstanz.betrag() |
| | ||
class Buchung: | class Buchung: | ||
Line 124: | Line 125: | ||
k1 = Konto(" | k1 = Konto(" | ||
k1.addBuchung(100, | k1.addBuchung(100, | ||
- | print k1.kontostand() | + | print k1.kontostand() |
</ | </ | ||
</ | </ | ||
Line 133: | Line 134: | ||
<hidden Lösungsvorschlag> | <hidden Lösungsvorschlag> | ||
- | <code python | + | <code python> |
from datetime import datetime | from datetime import datetime | ||
Line 183: | Line 184: | ||
print k1.kontostandDatum(" | print k1.kontostandDatum(" | ||
print k1.kontostandDatum(" | print k1.kontostandDatum(" | ||
- | </ | + | </ |
</ | </ | ||
Line 189: | Line 190: | ||
=== Präsentation === | === Präsentation === | ||
+ | {{lehrkraefte: | ||
=== Aufgabe 5 === | === Aufgabe 5 === | ||
+ | |||
+ | Fügen Sie bei Konto eine neue Methode " | ||
+ | |||
+ | <hidden Lösungsvorschlag> | ||
+ | <code python> | ||
+ | from datetime import datetime | ||
+ | |||
+ | class Konto: | ||
+ | def __init__(self, | ||
+ | self._inhaber = i | ||
+ | self._kontostand = k | ||
+ | self._buchungen = [] | ||
+ | |||
+ | def inhaber(self): | ||
+ | | ||
+ | |||
+ | def kontostand(self): | ||
+ | return self._kontostand | ||
+ | | ||
+ | def zinssatz(self): | ||
+ | return 0.035 | ||
+ | | ||
+ | def kontostandDatum(self, | ||
+ | datum = datetime.strptime(dString, | ||
+ | index = len(self._buchungen) - 1 | ||
+ | betrag = self._kontostand | ||
+ | while index >= 0 and datum < self._buchungen[index].datum(): | ||
+ | betrag = betrag - self._buchungen[index].betrag() | ||
+ | index = index - 1 | ||
+ | return betrag | ||
+ | | ||
+ | def addBuchung(self, | ||
+ | b = Buchung(b, d) | ||
+ | self._buchungen.append(b) | ||
+ | self._kontostand += b.betrag() | ||
+ | | ||
+ | class Supersparkonto (Konto): | ||
+ | def __init__(self, | ||
+ | Konto.__init__(self, | ||
+ | | ||
+ | def zinssatz(self): | ||
+ | abgehoben = 0 | ||
+ | for b in self._buchungen: | ||
+ | if b.betrag() < 0: | ||
+ | abgehoben += 1 | ||
+ | zins = Konto.zinssatz(self) | ||
+ | if abgehoben < 3: | ||
+ | zins += 0.01 | ||
+ | return zins | ||
+ | | ||
+ | class Buchung: | ||
+ | def __init__(self, | ||
+ | | ||
+ | | ||
+ | |||
+ | def betrag(self): | ||
+ | | ||
+ | |||
+ | def datum(self): | ||
+ | return self._datum | ||
+ | |||
+ | |||
+ | k1 = Supersparkonto(" | ||
+ | k1.addBuchung(-100, | ||
+ | k1.addBuchung(-200, | ||
+ | print k1.zinssatz() | ||
+ | k1.addBuchung(-300, | ||
+ | print k1.zinssatz() | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | === Aufgabe 6 === | ||
+ | |||
+ | Füge zur Klasse Konto eine Methode " | ||
+ | |||
+ | Zusatz: Natürlich ist es auch möglich, die korrekte Zinsgutschrift zu berechnen (wieviele Tage war welcher Betrag auf dem Konto). Wenn jemand mit allem fertig ist, kann das gerne versucht werden. | ||
+ | |||
+ | <hidden Lösungsvorschlag> | ||
+ | <code python> | ||
+ | from datetime import datetime | ||
+ | |||
+ | class Konto: | ||
+ | def __init__(self, | ||
+ | self._inhaber = i | ||
+ | self._kontostand = k | ||
+ | self._buchungen = [] | ||
+ | |||
+ | def inhaber(self): | ||
+ | | ||
+ | |||
+ | def kontostand(self): | ||
+ | return self._kontostand | ||
+ | | ||
+ | def zinssatz(self): | ||
+ | return 0.035 | ||
+ | | ||
+ | def kontostandDatum(self, | ||
+ | datum = datetime.strptime(dString, | ||
+ | index = len(self._buchungen) - 1 | ||
+ | betrag = self._kontostand | ||
+ | while index >= 0 and datum < self._buchungen[index].datum(): | ||
+ | betrag = betrag - self._buchungen[index].betrag() | ||
+ | index = index - 1 | ||
+ | return betrag | ||
+ | | ||
+ | def addBuchung(self, | ||
+ | b = Buchung(b, d) | ||
+ | self._buchungen.append(b) | ||
+ | self._kontostand += b.betrag() | ||
+ | | ||
+ | def jahresAbschluss(self): | ||
+ | self.addBuchung(self.kontostand() * self.zinssatz(), | ||
+ | | ||
+ | class Supersparkonto (Konto): | ||
+ | def __init__(self, | ||
+ | Konto.__init__(self, | ||
+ | | ||
+ | def zinssatz(self): | ||
+ | abgehoben = 0 | ||
+ | for b in self._buchungen: | ||
+ | if b.betrag() < 0: | ||
+ | abgehoben += 1 | ||
+ | zins = Konto.zinssatz(self) | ||
+ | if abgehoben < 3: | ||
+ | zins += 0.01 | ||
+ | return zins | ||
+ | | ||
+ | class Buchung: | ||
+ | def __init__(self, | ||
+ | | ||
+ | | ||
+ | |||
+ | def betrag(self): | ||
+ | | ||
+ | |||
+ | def datum(self): | ||
+ | return self._datum | ||
+ | |||
+ | |||
+ | k1 = Supersparkonto(" | ||
+ | k1.addBuchung(-100, | ||
+ | k1.addBuchung(-200, | ||
+ | k1.addBuchung(-300, | ||
+ | print k1.kontostand() | ||
+ | k1.jahresAbschluss() | ||
+ | print k1.kontostand() | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ |