You are not logged in.

  • Login

1

Monday, November 12th 2007, 12:46pm

Notizbuch Notizen Arraylist

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

2

Monday, November 12th 2007, 1:02pm

Ja, eigentlich genau wie du es geschrieben hast.

Java Quellcode

1
ArrayList<Notiz> notizen = new ArrayList<Notiz>;();

3

Monday, November 12th 2007, 1:25pm

Dann bekomm ich aber in Zeile 17 von der Klasse Notizbuch

Quoted

notizen.add(notiz);
einen Fehler.

cannot find symbol - method add(java.lang.String)

4

Monday, November 12th 2007, 8:49pm

Das wird dann natürlich auch ein Notiz Objekt sein

Java Quellcode

1
public void speichereNotiz(Notiz notiz) { ...

Similar threads

Social bookmarks