シンボルが見つけられませんのエラーを消すことができない。
- 評価
- クリップ 0
- VIEW 337
すみません。Java初心者です。まだ質問の仕方にあまりうまく慣れていないのですが少し教えていただきたいことがあり質問します。現在人物紹介プログラムを書いており一応個人的には書きおわったとかんがえているのですがエラー文の中にあるシンボルが見つけられませんというエラーを消すことができません。具体的には(初心者なので見間違っているかもしれませんがperson_oneやpが認識されないと出ます。)文章がうまくまとめられないでいるのも大変悪いと思いますが何か意見をいただけたら幸いです。ご気分を害されたらすいません。
コード
class DateOfBirth {
int birth_year;
int birth_month;
int birth_date;
boolean known;
}
class Myfriend {
String name;
DateOfBirth the_date_of_birth;
String phone_number;
}
class Person {
String name;
DateOfBirth the_date_of_birth;
String phone_number;
int n_of_friends;
Myfriend[] friend;
}
class ex6_2 {
public static void main(String args[]) {
Person person_one;
Person person_two;
person_one = new Person();
person_two = new Person();
/* for protection of personal data, pseudo values are used */
person_one.name = "A";
person_one.the_date_of_birth = new DateOfBirth();
person_one.the_date_of_birth.known = true;
person_one.the_date_of_birth.birth_year = 2004;
person_one.the_date_of_birth.birth_month = 12;
person_one.the_date_of_birth.birth_date = 3;
person_one.phone_number = "080-1234-5678";
person_two.name = "B";
person_two.the_date_of_birth = new DateOfBirth();
person_two.the_date_of_birth.known = true;
person_two.the_date_of_birth.birth_year = 2004;
person_two.the_date_of_birth.birth_month = 1;
person_two.the_date_of_birth.birth_date = 23;
person_two.phone_number = "090-8765-4321";
/* person_one believes that the 'person_two' is a friend */
person_one.n_of_friends = 1;
person_one.friend = new Myfriend[1];
person_one.friend[0] = new Myfriend();
person_one.friend[0].name = person_two.name;
person_one.friend[0].the_date_of_birth = new DateOfBirth();
person_one.friend[0].the_date_of_birth.birth_year
= person_two.the_date_of_birth.birth_year;
person_one.friend[0].the_date_of_birth.birth_month
= person_two.the_date_of_birth.birth_month;
person_one.friend[0].the_date_of_birth.birth_date
= person_two.the_date_of_birth.birth_date;
person_one.friend[0].the_date_of_birth.known
= person_two.the_date_of_birth.known;
person_one.friend[0].phone_number = person_two.phone_number;
/* however, person_two does not think so. */
person_two.n_of_friends = 0;
/* print the input data */
print_personal_info(person_one);
print_personal_info(person_two);
}
static void print_personal_info(Person p) {
int i;
String person_one;
System.out.print("NAME: " + person_one.name + "\n");
System.out.print("Date of Birth: " + p.the_date_of_birth.birth_year
+ " " + p.the_date_of_birth.birth_month
+ " " + p.the_date_of_birth.birth_date + "\n");
System.out.print("Number of friends = " + p.n_of_friends + "\n");
for( i = 0; i < p.n_of_friends; i++ ) {
System.out.print("Name of friend " + i
+ ": " + p.friend[i].name + "\n");
if( p.friend[i].the_date_of_birth.known == true ) {
System.out.print("Date of Birth: "
+ p.friend[i].the_date_of_birth.birth_year
+ " "
+ p.friend[i].the_date_of_birth.birth_month
+ " "
+ p.friend[i].the_date_of_birth.birth_date
+ "\n");
} else {
System.out.print(" Date of birth is unknown.\n");
}
}
}
}
(実行結果)
DateOfBirth.java:76: エラー: シンボルを見つけられません
System.out.print("NAME: " + person_one.name + "\n");
^
シンボル: 変数 name
場所: タイプStringの変数 person_one
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
+1
まず、全体的にpublic static void main(String args[])
が不要です。
mainメソッドはプログラムを起動するためのメソッドなので1箇所でいいです。
おそらくex6_2
クラスが実行クラスだと思うので、ここだけでいいような気がします。
以下のような感じにしてみましょう。
class DateOfBirth {
int birth_year;
int birth_month;
int birth_date;
boolean known;
}
class Myfriend {
String name;
DateOfBirth the_date_of_birth;
String phone_number;
}
class Person {
String name;
DateOfBirth the_date_of_birth;
String phone_number;
int n_of_friends;
Myfriend[] friend;
}
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
0
static void print_personal_info(Person p) {
int i;
System.out.print("NAME: " + person_one.name + "\n");
このperson_one が未定義ですね
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 89.99%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
y_waiwai
2018/11/08 10:39
実際のエラーメッセージを、加工や省略せずそのまま提示してください
shou_hitotose
2018/11/08 10:40
あ、すみません。わかりました。