質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

解決済

2回答

302閲覧

シンボルが見つけられませんのエラーを消すことができない。

shou_hitotose

総合スコア66

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2018/11/08 01:36

編集2018/11/08 01:59

すみません。Java初心者です。まだ質問の仕方にあまりうまく慣れていないのですが少し教えていただきたいことがあり質問します。現在人物紹介プログラムを書いており一応個人的には書きおわったとかんがえているのですがエラー文の中にあるシンボルが見つけられませんというエラーを消すことができません。具体的には(初心者なので見間違っているかもしれませんがperson_oneやpが認識されないと出ます。)文章がうまくまとめられないでいるのも大変悪いと思いますが何か意見をいただけたら幸いです。ご気分を害されたらすいません。

Java

1コード 2class DateOfBirth { 3 4 int birth_year; 5 int birth_month; 6 int birth_date; 7 boolean known; 8 9} 10class Myfriend { 11 12 String name; 13 DateOfBirth the_date_of_birth; 14 String phone_number; 15 16} 17class Person { 18 19 String name; 20 DateOfBirth the_date_of_birth; 21 String phone_number; 22 int n_of_friends; 23 Myfriend[] friend; 24 25} 26 27class ex6_2 { 28 public static void main(String args[]) { 29 Person person_one; 30 Person person_two; 31 person_one = new Person(); 32 person_two = new Person(); 33 34 /* for protection of personal data, pseudo values are used */ 35 person_one.name = "A"; 36 person_one.the_date_of_birth = new DateOfBirth(); 37 person_one.the_date_of_birth.known = true; 38 person_one.the_date_of_birth.birth_year = 2004; 39 person_one.the_date_of_birth.birth_month = 12; 40 person_one.the_date_of_birth.birth_date = 3; 41 person_one.phone_number = "080-1234-5678"; 42 43 person_two.name = "B"; 44 person_two.the_date_of_birth = new DateOfBirth(); 45 person_two.the_date_of_birth.known = true; 46 person_two.the_date_of_birth.birth_year = 2004; 47 person_two.the_date_of_birth.birth_month = 1; 48 person_two.the_date_of_birth.birth_date = 23; 49 person_two.phone_number = "090-8765-4321"; 50 51 /* person_one believes that the 'person_two' is a friend */ 52 person_one.n_of_friends = 1; 53 person_one.friend = new Myfriend[1]; 54 person_one.friend[0] = new Myfriend(); 55 person_one.friend[0].name = person_two.name; 56 person_one.friend[0].the_date_of_birth = new DateOfBirth(); 57 person_one.friend[0].the_date_of_birth.birth_year 58 = person_two.the_date_of_birth.birth_year; 59 person_one.friend[0].the_date_of_birth.birth_month 60 = person_two.the_date_of_birth.birth_month; 61 person_one.friend[0].the_date_of_birth.birth_date 62 = person_two.the_date_of_birth.birth_date; 63 person_one.friend[0].the_date_of_birth.known 64 = person_two.the_date_of_birth.known; 65 person_one.friend[0].phone_number = person_two.phone_number; 66 67 /* however, person_two does not think so. */ 68 person_two.n_of_friends = 0; 69 70 /* print the input data */ 71 print_personal_info(person_one); 72 print_personal_info(person_two); 73 } 74 static void print_personal_info(Person p) { 75 int i; 76 String person_one; 77 System.out.print("NAME: " + person_one.name + "\n"); 78 System.out.print("Date of Birth: " + p.the_date_of_birth.birth_year 79 + " " + p.the_date_of_birth.birth_month 80 + " " + p.the_date_of_birth.birth_date + "\n"); 81 System.out.print("Number of friends = " + p.n_of_friends + "\n"); 82 for( i = 0; i < p.n_of_friends; i++ ) { 83 System.out.print("Name of friend " + i 84 + ": " + p.friend[i].name + "\n"); 85 if( p.friend[i].the_date_of_birth.known == true ) { 86 System.out.print("Date of Birth: " 87 + p.friend[i].the_date_of_birth.birth_year 88 + " " 89 + p.friend[i].the_date_of_birth.birth_month 90 + " " 91 + p.friend[i].the_date_of_birth.birth_date 92 + "\n"); 93 } else { 94 System.out.print(" Date of birth is unknown.\n"); 95 } 96 } 97 } 98}

(実行結果)
DateOfBirth.java:76: エラー: シンボルを見つけられません
System.out.print("NAME: " + person_one.name + "\n");
^
シンボル: 変数 name
場所: タイプStringの変数 person_one

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2018/11/08 01:39

実際のエラーメッセージを、加工や省略せずそのまま提示してください
shou_hitotose

2018/11/08 01:40

あ、すみません。わかりました。
guest

回答2

0

ベストアンサー

まず、全体的にpublic static void main(String args[])が不要です。
mainメソッドはプログラムを起動するためのメソッドなので1箇所でいいです。
おそらくex6_2クラスが実行クラスだと思うので、ここだけでいいような気がします。

以下のような感じにしてみましょう。

Java

1class DateOfBirth { 2 int birth_year; 3 int birth_month; 4 int birth_date; 5 boolean known; 6} 7 8class Myfriend { 9 String name; 10 DateOfBirth the_date_of_birth; 11 String phone_number; 12} 13 14class Person { 15 String name; 16 DateOfBirth the_date_of_birth; 17 String phone_number; 18 int n_of_friends; 19 Myfriend[] friend; 20}

投稿2018/11/08 01:49

root_jp

総合スコア4666

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shou_hitotose

2018/11/08 01:51

回答ありがとうございます!やってみます!!
shou_hitotose

2018/11/08 02:06

無事解決することができました!ありがとうございます!
guest

0

static void print_personal_info(Person p) {

int i; System.out.print("NAME: " + person_one.name + "\n");

このperson_one が未定義ですね

投稿2018/11/08 01:41

y_waiwai

総合スコア87747

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shou_hitotose

2018/11/08 01:44

あ、わかりました!やってみます!
shou_hitotose

2018/11/08 01:44

こんなにも早くのご回答ありがとうございます!!!!!
shou_hitotose

2018/11/08 01:47

person_oneをpに変えたのですがp自体もシンボルが見つけられませんとなってしまうのですが・・。
y_waiwai

2018/11/08 01:50

実際のエラーメッセージを提示してみてください
shou_hitotose

2018/11/08 01:53

かしこまりました。一応root_jpさんに教えていただいた処理をしたあとの実行結果を送ります。
shou_hitotose

2018/11/08 02:06

お二人の意見を聞き無事問題を解決することができました!ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問