0
Arrayインデックスに格納されているTokenオブジェクトのString名を出力しようとしています。私が得るのは、おそらく場所アドレスのように見えるトークン@です。私はそれがそのオブジェクトの文字列を印刷したい。1次元配列に格納されたオブジェクトの特定の文字列を印刷する
import java.util.Scanner;
public class MainBoardDriver
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Squares[] squareArray = new Squares[40]; // Creates an array to store properties
squareArray[0] = new GoSquare("Gp");
squareArray[1] = new PropertySquares("Mediterranean Avenue", 60, "purple");
squareArray[2] = new CommunityChestSquares("Community Chest");
squareArray[3] = new PropertySquares("Baltic Avenue", 60, "purple");
squareArray[4] = new TaxSquares("Income Tax", 200);
squareArray[5] = new RailroadSquares("Reading Railroad", 200);
squareArray[6] = new PropertySquares("Oriental Avenue", 100, "Light Blue");
squareArray[7] = new ChanceSquares("Chance");
squareArray[8] = new PropertySquares("Vermont Avenue", 100, "Light Blue");
squareArray[9] = new PropertySquares("Connecticut Avenue", 100, "Light Blue");
squareArray[10] = new InJailJustVisitingSquare("In Jail or Just Visiting");
squareArray[11] = new PropertySquares("St. Charles Place", 140, "Pink");
squareArray[12] = new UtilitySquares("Electric Company", 150);
squareArray[13] = new PropertySquares("States Avenue", 140, "Pink");
squareArray[14] = new PropertySquares("Virginia Avenue", 160, "Pink");
squareArray[15] = new RailroadSquares("Pennsylvania Railroad", 200);
squareArray[16] = new PropertySquares("St. James Place", 180, "Orange");
squareArray[17] = new CommunityChestSquares("Community Chest");
squareArray[18] = new PropertySquares("Tennessee Avenue", 180, "Orange");
squareArray[19] = new PropertySquares("New York Avenue", 200, "Orange");
squareArray[20] = new FreeParkingSquare("Free Parking");
squareArray[21] = new PropertySquares("kentucky Avenue", 220, "Red");
squareArray[22] = new ChanceSquares("Chance");
squareArray[23] = new PropertySquares("Indiana Avenue", 220, "Red");
squareArray[24] = new PropertySquares("Illinois Avenue", 240, "Red");
squareArray[25] = new RailroadSquares("B. & O. Railroad", 200);
squareArray[26] = new PropertySquares("Atlantic Avenue", 260, "Yellow");
squareArray[27] = new PropertySquares("Ventnor Avenue", 260, "Yellow");
squareArray[28] = new UtilitySquares("Water Works", 150);
squareArray[29] = new PropertySquares("Marvin Gardens", 280, "Yellow");
squareArray[30] = new GoToJailSquare("Go To Jail");
squareArray[31] = new PropertySquares("Pacific Avenue", 300, "Green");
squareArray[32] = new PropertySquares("North Carolina Avenue", 300, "Green");
squareArray[33] = new CommunityChestSquares("Community Chest");
squareArray[34] = new PropertySquares("Pennsylvania Avenue", 320, "Green");
squareArray[35] = new RailroadSquares("Short Line", 200);
squareArray[36] = new ChanceSquares("Chance");
squareArray[37] = new PropertySquares("Park Place", 350, "Blue");
squareArray[38] = new TaxSquares("Luxuary Tax", 100);
squareArray[39] = new PropertySquares("Boardwalk", 400, "Blue");
System.out.println("Enter the number of players: ");
int numPlayers = scan.nextInt();
Token[] tokenArray = new Token[8]; // Creates an array to store objects
tokenArray[0] = new Token("Battle Ship", 0, 1500);
tokenArray[1] = new Token("Top Hat", 0, 1500);
tokenArray[2] = new Token("Dog", 0, 1500);
tokenArray[3] = new Token("Boot", 0, 1500);
tokenArray[4] = new Token("Wheel Barrow", 0, 1500);
tokenArray[5] = new Token("Race Car", 0, 1500);
tokenArray[6] = new Token("Thimble", 0, 1500);
tokenArray[7] = new Token("Cat", 0, 1500);
for(int i = 1; i <= numPlayers; i++) // loop to for players to chose a token
{
System.out.println("Player " + i + " Chose a token: ");
int userChoice = scan.nextInt();
System.out.println("You chose: " + tokenArray[userChoice].gettoString()); //
}
}
}
私はそれを理解したと信じています...多分私はちょっとした睡眠が必要でした。 – CaptainChadL