すみません。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
回答2件
あなたの回答
tips
プレビュー