前提・実現したいこと
二次元配列を用いて表示したいのですが、オブジェクト指向と二次元配列の結びつけがうまくできません。ごちゃごちゃですがヒントとなることを教えていただきたいです。どうかよろしくお願い致します。
問題文
Othelloクラスにthisを利用したコンストラクタを追加。フィールド変数のためのアクセサメソッドを追加し,カプセル化。
Othelloクラスを利用して1つのオブジェクトを作成する実行クラスを作成。アクセサメソッドを利用して以下の出力が得られるよう値の再設定、表示を行いなさい。ここでは,拡張forを利用して表示するものとする.
表示結果
o o o
o x x
o x o
x o x
o x o
x x o
書いたプログラム
import java.util.*;
public class Main {
public static void main(String args[] ){
Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"});
a.show();
System.out.println();
a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"});
a.show();
}
}
class Othello {
char[][] board;
public Othello(char[][] board){ this.board=board; } public void setBoard(char n){ board = n; } public char getBoard(){ return board; } public void show(){ for(int m=0;m<3;m++){ for(int i=0;i<3;i++){ System.out.print(board[m][i]+" "); } } }
}
発生している問題・エラーメッセージ
illegal start of expression Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: illegal start of type Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: expected Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: not a statement Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: ';' expected Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: illegal start of expression Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: not a statement Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: ';' expected Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:6: error: illegal start of expression Othello a = new Othello({"o","o","o"},{"o","x","x"},{"o","x","o"}); ^ Main.java:9: error: illegal start of expression a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: not a statement a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: ';' expected a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: illegal start of expression a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: not a statement a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: ';' expected a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: illegal start of expression a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: not a statement a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: ';' expected a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ Main.java:9: error: illegal start of expression a.setName({"x","o","x"},{"o","x","o"},{"x","x","o"}); ^ 19 errors
該当のソースコード
java
試したこと
わかりやすいJavaオブジェクト指向、などの教科書を参照
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/09 14:40
2020/06/09 14:49
2020/06/09 14:57