Last active
April 8, 2024 14:13
-
-
Save Geolykt/f54f0d48cac73743d508227f38269185 to your computer and use it in GitHub Desktop.
This file contains 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 Beitrag { | |
private DateTime gepostet; | |
private String titel; | |
private int anzahlLikes; | |
private String text; | |
private ArrayList<Bild> bilder; | |
private Nutzer autor; | |
public Beitrag(Nutzer autor, String titel, Bild bild) { | |
this.gepostet = new DateTime(); | |
this.author = author; | |
this.titel = titel; | |
this.anzahlLikes = 0; | |
this.text = null; | |
this.bilder = new ArrayList<>(); | |
this.bilder.add(bild); | |
} | |
public void hinzufuegen(Bild bild) { | |
this.bilder.add(bild); | |
} | |
public void erstelleText(String text) { | |
this.text = text; | |
} | |
public void like() { | |
this.anzahlLikes = this.anzahlLikes + 1; | |
} | |
} |
This file contains 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 Nutzer { | |
private ArrayList<Bild> bilder; | |
private ArrayList<Beitrag> beitraege; | |
private ArrayList<Nutzer> abonnierteNutzer; | |
private ArrayList<Nutzer> abonnenten; | |
private String benutzerName; | |
private String passwort; | |
private String emailAdresse; | |
private DateTime zuletztAktiv; | |
public Nutzer(String name, String passwort, String email) { | |
this.bilder = new ArrayList<>(); | |
this.beitraege = new ArrayList<>(); | |
this.abonnierteNutzer = new ArrayList<>(); | |
this.abonnenten = new ArrayList<>(); | |
this.benutzerName = name; | |
this.passwort = passwort; | |
this.emailAdresse = email; | |
this.zuletztAktiv = new DateTime(); | |
} | |
public Beitrag erstelleBeitrag(String titel, Bild bild) { | |
return this.erstelleBeitrag(titel, bild, null); | |
} | |
public Beitrag erstelleBeitrag(String titel, Bild bild, String text) { | |
Beitrag beitrag = new Beitrag(this, titel, bild); | |
if (text != null) { | |
beitrag.erstelleText(text); | |
} | |
this.beitraege.add(beitrag); | |
this.zuletztAktiv = new DateTime(); | |
// Müsste hier this.hinzufuegenBild(bild) sein? Ich weiß es nicht so ganz. | |
return beitrag; | |
} | |
public void abonnieren(Nutzer n) { | |
boolean bereitsAbonniert = false; | |
for (Nutzer nutzer2 : this.abonnierteNutzer) { | |
if (nutzer2.equals(n)) { | |
bereitsAbonniert = true; | |
} | |
} | |
if (!bereitsAbonniert) { | |
this.abonnierteNutzer.add(n); | |
n.abonnenten.add(this); | |
this.zuletztAktiv = new DateTime(); | |
} | |
} | |
public void like(Beitrag beitrag) { | |
if (!beitrag.getAutor().equals(this)) { // Technisch gesehen wäre != genauso wie !a.equals(b) zu sehen. | |
this.beitrag.like(); | |
this.zuletztAktiv = new DateTime(); | |
} | |
} | |
public void hinzufuegenBild(Bild bild) { | |
this.bilder.add(bild); | |
this.zuletztAktiv = new DateTime(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment