Notizbuch Notizen Arraylist

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Notizbuch Notizen Arraylist

    Habe mal wieder ein kleines Problem mit Arraylist.


    Undzwar habe ich eine Notizbuchklasse

    Quellcode

    1. import java.util.ArrayList;
    2. public class Notizbuch
    3. {
    4. // Speicher für eine beliebige Anzahl an Emails.
    5. private ArrayList<String> notizen;
    6. public Notizbuch()
    7. {
    8. notizen = new ArrayList<String>;();
    9. }
    10. public void speichereNotiz(String notiz)
    11. {
    12. notizen.add(notiz);
    13. }
    14. public int anzahlNotizen()
    15. {
    16. return notizen.size();
    17. }
    18. public void zeigeNotiz(int notiznummer)
    19. {
    20. if(notiznummer < 0) {
    21. // Keine gültige Nummer, nichts zu tun.
    22. }
    23. else if(notiznummer < anzahlNotizen()) {
    24. // Die Nummer ist gültig, wir können die Notiz ausgeben.
    25. System.out.println(notizen.get(notiznummer));
    26. }
    27. else {
    28. // Keine gültige Nummer, nichts zu tun.
    29. }
    30. }
    31. }
    Alles anzeigen



    und eine Notizklasse

    Quellcode

    1. public class Notiz
    2. {
    3. private String tag;
    4. private int stunde;
    5. private String info;
    6. public Notiz(String tag, int stunde, String info)
    7. {
    8. this.tag = tag;
    9. this.stunde = stunde;
    10. this.info = info;
    11. }
    12. public String getTag()
    13. {
    14. return tag;
    15. }
    16. public int getStunde()
    17. {
    18. return stunde;
    19. }
    20. public String getInfo()
    21. {
    22. return info;
    23. }
    24. }
    Alles anzeigen



    Nun will ich in der Notizenklasse Notizen reinschreiben, die dann im Notizbuch ausgegeben werden.

    Muss ich dazu

    Quellcode

    1. ArrayList<String>
    in

    Quellcode

    1. ArrayList<Notiz>
    ändern????

    Bzw. wie realisier ich das????


    Danke für alle antworten