0

Let me start by saying that I'm only beginning to learn java, so this will (probably) be a beginner question. Im getting a pointer return instead of an array with dice rolls. 3 Classes, Tienduizend, Roll and Player.

Tienduizend:

package tienduizend;

import java.util.Scanner;

public class Tienduizend {

public static void main(String[] args) {

    Roll roll = new Roll(5);

    Scanner Scan = new Scanner(System.in);
    System.out.println("Speler 1 naam: ");
    Player player1 = new Player(Scan.nextLine(), 0, 5);
    System.out.println("Speler 2 naam: ");
    Player player2 = new Player(Scan.nextLine(), 0, 5);

    System.out.println(player1.getName() + " is aan zet:");
    System.out.print(player1.getName() + " gooit: ");

    System.out.print(roll.getRoll());
}
}

Roll:

package tienduizend;

import java.util.Random;

public class Roll {

private int[] roll;
private int[] keep = new int[5];
private int toRoll;

public Roll(int rolls) {
    roll = new int[rolls];
    for (int i = 0; i < rolls; i++) {
        roll[i] = rollDice();
    }
}

public int rollDice() {
    Random rand = new Random();
    return rand.nextInt(6) + 1;
}

public int[] getRoll() {
    return roll;
}

public int getTempScore(int[] a) {
    return 100;
}

public int getFinalScore() {
    return 1000;
}
}

Player:

package tienduizend;

public class Player {

private int totalScore;
private String name;
private int toRoll;

public Player(String name, int totalScore, int toRoll) {
    this.name = name;
    this.totalScore = totalScore;
    this.toRoll = toRoll;
}

public String getName() {
    return name;
}

public int getTotalScore() {
    return totalScore;
}

public void setTotalScore(int totalScore) {
    this.totalScore = totalScore;
}

public int getToRoll() {
    return toRoll;
}

public void setToRoll(int toRoll) {
    this.toRoll = toRoll;
}

}

Wheres my mistake and how so I fix it? Thanks in advance !

In short by request; calling:

System.out.print(roll.getRoll());

gives me:

[I@1b6d3586

while it should return an array of dice rolls. (like 1,2,3,4,5)

Koen
  • 461
  • 2
  • 5
  • 16
  • "A pointer return"? Do you mean a `NullPointerExeption`? – kolossus Nov 18 '14 at 21:17
  • Tried to use terms I dont know yet lol, what I mean is when I call System.out.print(roll.getRoll()); I get: [I@1b6d3586 as a result – Koen Nov 18 '14 at 21:19
  • Please post a short code sample (as short as you can make it while keeping it a complete program) along with what you expect to see and what you do see, as precisely as possible. That will help us answer the question, since right now there's a lot of excess stuff that makes it hard to hone in on exactly what you're asking. – yshavit Nov 18 '14 at 21:19
  • Ah, your problem is in the standard `toString` representation of arrays. See http://stackoverflow.com/questions/7060016 – yshavit Nov 18 '14 at 21:20
  • You are printing the array, not the values contained in the array. – The Head Rush Nov 18 '14 at 21:23

0 Answers0