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)