私には2つのクラスがHangman
ありwords
、次のとおりです。
絞首刑執行人クラス:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hangman;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author Adam2_000
*/
public class Hangman {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String player = "";
String selection;
Scanner scan = new Scanner(System.in);
words words = new words();
String easyWords1[] = words.easyWords;
String mediumWords1[] = words.mediumWords;
String hardWords1[] = words.hardWords;
System.out.println("Welcome to Hangman version 1");
System.out.println("Please choose a difficulty");
System.out.println("A: Easy");
System.out.println("B: Medium");
System.out.println("C: Hard");
char iChoice;
do {
selection = scan.nextLine().toUpperCase();
} while (selection.isEmpty());
iChoice = selection.charAt(0);
if (iChoice != 'X') {
switch (iChoice) {
case 'A':
System.out.println("You have choosen easy:");
System.out.println(words.getEasyWords());
break;
case 'B':
System.out.println("You have choosen Medium");
System.out.println(words.getMediumWords());
break;
case 'C':
System.out.println("You have choosen Hard");
System.out.println(words.getHardWords());
break;
}
}
}
}
単語クラス:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hangman;
import java.lang.reflect.Array;
import java.util.Random;
/**
*
* @author Adam2_000
*/
public class words extends Hangman {
String[] easyWords = {"Bee", "Car", "Fish", "Shed"};
String[] mediumWords = {"House", "Sheep", "Castle", "Phone"};
String[] hardWords = {"Octagon", "Crocodile", "Chocolate", "Motorbike"};
public String[] getEasyWords() {
return easyWords;
}
public void setEasyWords(String[] easyWords) {
this.easyWords = easyWords;
}
public String[] getMediumWords() {
return mediumWords;
}
public void setMediumWords(String[] mediumWords) {
this.mediumWords = mediumWords;
}
public String[] getHardWords() {
return hardWords;
}
public void setHardWords(String[] hardWords) {
this.hardWords = hardWords;
}
@Override
public String toString() {
return "words{" + "easyWords=" + easyWords + ", mediumWords=" + mediumWords + ", hardWords=" + hardWords + '}';
}
}
各配列を表示しようとすると、文字列ではなく参照を取得しています。誰か助けてくれませんか?