Results 1 to 2 of 2
- 03-19-2009, 02:46 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
Printing the contents of an array of objects
Hello,
I'm working on a piece of code and I can't figure out how to print the contents in my array, that exists out of an object. I have two classes, one called HanzeBank and one called Bankrekening.
I just added a method in Hanzebank that makes a new Bankrekening object and puts this in an array in Hanzebank. Here's the code for this.
And the code in Bankrekening:public void addRekening(String naam, int rekeningnummer, int saldo){
Bankrekening rekening = new Bankrekening();
rekening.rekening(naam, rekeningnummer, saldo);
bank.add(rekening);
}
Now this is working, I'm making a method to print the name(naam), accountnumber(rekeningnummer) and the amount of money on the account(saldo).public void rekening(String naam, int rekeningnummer, int saldo){
if(0 == 1){
System.out.println("Rekeningnummer " + rekeningnummer + " is al in gebruik");
} else {
this.naam = naam;
this.rekeningnummer = rekeningnummer;
this.saldo = saldo;
System.out.println("Rekening succesvol aangemaakt!");
}
}
In Bankrekening I have three methods that return these variables. Here's the code for that:
Now I want to use this methods in Hanzebank to print the information so I tried the following:public void getName(){
System.out.println(naam);
}
public void getNumber(){
System.out.println(rekeningnummer);
}
public void getSaldo(){
System.out.println(saldo);
}
This doesn't work, I tried tons of other ways to print this, but none of it works. Can anyone help me please?public void showRekeningen(){
for(int i=0; i<numberOfRekeningen(); i++){
System.out.println(bank.getName());
}
}
Gr.
Mr.Paplu
[edit] Btw, I also tried finding this on the internet, but all I found is what I already got.
- 03-19-2009, 04:49 PM #2
System.out.println returns void. so when you call:
System.out.println(bank.getName());
you are calling:
System.out.println(System.out.println(naam));USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Similar Threads
-
Printing Array elements
By new person in forum New To JavaReplies: 2Last Post: 02-23-2009, 08:57 PM -
printing an array of String through drawString
By kaemonsaionji in forum New To JavaReplies: 1Last Post: 02-23-2009, 04:38 PM -
printing array
By mayhewj7 in forum New To JavaReplies: 6Last Post: 02-12-2009, 02:01 PM -
Printing Byte Array
By suchismitasuchi in forum New To JavaReplies: 3Last Post: 01-19-2009, 10:58 AM -
Printing contents of a web page
By Java Tip in forum Java TipReplies: 0Last Post: 11-26-2007, 12:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks