Habe mal wieder ein kleines Problem mit Arraylist.
Undzwar habe ich eine Notizbuchklasse
|
Java Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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
|
Java Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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
|
Java Quellcode
|
1
|
ArrayList<String>
|
in
|
Java Quellcode
|
1
|
ArrayList<Notiz>
|
ändern????
Bzw. wie realisier ich das????
Danke für alle antworten