Habe mal wieder ein kleines Problem mit Arraylist.
Undzwar habe ich eine Notizbuchklasse
Alles anzeigen
und eine Notizklasse
Alles anzeigen
Nun will ich in der Notizenklasse Notizen reinschreiben, die dann im Notizbuch ausgegeben werden.
Muss ich dazu
in ändern????
Bzw. wie realisier ich das????
Danke für alle antworten
Undzwar habe ich eine Notizbuchklasse
Quellcode
- import java.util.ArrayList;
- public class Notizbuch
- {
- // Speicher für eine beliebige Anzahl an Emails.
- private ArrayList<String> notizen;
- public Notizbuch()
- {
- notizen = new ArrayList<String>;();
- }
- public void speichereNotiz(String notiz)
- {
- notizen.add(notiz);
- }
- public int anzahlNotizen()
- {
- return notizen.size();
- }
- public void zeigeNotiz(int notiznummer)
- {
- if(notiznummer < 0) {
- // Keine gültige Nummer, nichts zu tun.
- }
- else if(notiznummer < anzahlNotizen()) {
- // Die Nummer ist gültig, wir können die Notiz ausgeben.
- System.out.println(notizen.get(notiznummer));
- }
- else {
- // Keine gültige Nummer, nichts zu tun.
- }
- }
- }
und eine Notizklasse
Quellcode
- public class Notiz
- {
- private String tag;
- private int stunde;
- private String info;
- public Notiz(String tag, int stunde, String info)
- {
- this.tag = tag;
- this.stunde = stunde;
- this.info = info;
- }
- public String getTag()
- {
- return tag;
- }
- public int getStunde()
- {
- return stunde;
- }
- public String getInfo()
- {
- return info;
- }
- }
Nun will ich in der Notizenklasse Notizen reinschreiben, die dann im Notizbuch ausgegeben werden.
Muss ich dazu
in ändern????
Bzw. wie realisier ich das????
Danke für alle antworten