Results 1 to 2 of 2
  1. #1
    Mr.Paplu is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default 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.
    public void addRekening(String naam, int rekeningnummer, int saldo){
    Bankrekening rekening = new Bankrekening();
    rekening.rekening(naam, rekeningnummer, saldo);
    bank.add(rekening);
    }
    And the code in Bankrekening:
    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!");
    }
    }
    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).
    In Bankrekening I have three methods that return these variables. Here's the code for that:
    public void getName(){
    System.out.println(naam);
    }
    public void getNumber(){
    System.out.println(rekeningnummer);
    }
    public void getSaldo(){
    System.out.println(saldo);
    }
    Now I want to use this methods in Hanzebank to print the information so I tried the following:
    public void showRekeningen(){
    for(int i=0; i<numberOfRekeningen(); i++){
    System.out.println(bank.getName());
    }
    }
    This doesn't work, I tried tons of other ways to print this, but none of it works. Can anyone help me please?

    Gr.

    Mr.Paplu

    [edit] Btw, I also tried finding this on the internet, but all I found is what I already got.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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

  1. Printing Array elements
    By new person in forum New To Java
    Replies: 2
    Last Post: 02-23-2009, 08:57 PM
  2. printing an array of String through drawString
    By kaemonsaionji in forum New To Java
    Replies: 1
    Last Post: 02-23-2009, 04:38 PM
  3. printing array
    By mayhewj7 in forum New To Java
    Replies: 6
    Last Post: 02-12-2009, 02:01 PM
  4. Printing Byte Array
    By suchismitasuchi in forum New To Java
    Replies: 3
    Last Post: 01-19-2009, 10:58 AM
  5. Printing contents of a web page
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-26-2007, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •