また質問を投稿させていただきます。なかなかプログラムが完成しないものですのですみません。例の如く自己紹介プログラムを書いているのですがまたエラーが出てしまいました。おそらくクラスを配置すればいいのでしょうがどこにどう配置すればよいのかがわかりませんでした。ご意見などをいただけると幸いです。
Java
1class DateOfBirth { 2 3 int birth_year; 4 int birth_month; 5 int birth_date; 6 boolean known; 7 8} 9class Myfriend { 10 11 String name; 12 DateOfBirth the_date_of_birth; 13 String phone_number; 14 15} 16class Person { 17 String name; 18 19 DateOfBirth the_date_of_birth; 20 String phone_number; 21 int n_of_friends; 22 Myfriend[] friend; 23 24} 25 26 public int year; 27 public int month; 28 public int day; 29 30 31 32class ex6_2 { 33 34 public static void main(String args[]) { 35 Person person_one; 36 Person person_two; 37 person_one = new Person(); 38 person_two = new Person(); 39 40 /* for protection of personal data, pseudo values are used */ 41 person_one.name = "A"; 42 person_one.the_date_of_birth = new DateOfBirth(); 43 person_one.the_date_of_birth.known = true; 44 Birth birth_year1=new Birth(); 45 46 birth_year1.birthday(2004,3,3); 47 48 49 person_one.phone_number = "080-1234-5678"; 50 51 person_two.name = "Adolf Brain Charles David Frederic John"; 52 person_two.the_date_of_birth = new DateOfBirth(); 53 person_two.the_date_of_birth.known = true; 54 Birth birth_year2=new Birth(); 55 birth_year2.birthday(2004,1,23); 56 person_two.phone_number = "090-8765-4321"; 57 58 /* person_one believes that the 'person_two' is a friend */ 59 person_one.n_of_friends = 1; 60 person_one.friend = new Myfriend[1]; 61 person_one.friend[0] = new Myfriend(); 62 person_one.friend[0].name = person_two.name; 63 person_one.friend[0].the_date_of_birth = new DateOfBirth(); 64 person_one.friend[0].the_date_of_birth.birth_year 65 = person_two.the_date_of_birth.birth_year; 66 person_one.friend[0].the_date_of_birth.birth_month 67 = person_two.the_date_of_birth.birth_month; 68 person_one.friend[0].the_date_of_birth.birth_date 69 = person_two.the_date_of_birth.birth_date; 70 person_one.friend[0].the_date_of_birth.known 71 = person_two.the_date_of_birth.known; 72 person_one.friend[0].phone_number = person_two.phone_number; 73 74 /* however, person_two does not think so. */ 75 person_two.n_of_friends = 0; 76 77 /* print the input data */ 78 print_personal_info(person_one); 79 print_personal_info(person_two); 80 } 81 static void print_personal_info(Person p) { 82 int i; 83 84 System.out.print("NAME: " + p.name + "\n"); 85 86 System.out.print("Number of friends = " + p.n_of_friends + "\n"); 87 for( i = 0; i < p.n_of_friends; i++ ) { 88 System.out.print("Name of friend " + i 89 + ": " + p.friend[i].name + "\n"); 90 if( p.friend[i].the_date_of_birth.known == true ) { 91 System.out.print("Date of Birth: " 92 + p.friend[i].the_date_of_birth.birth_year 93 + " " 94 + p.friend[i].the_date_of_birth.birth_month 95 + " " 96 + p.friend[i].the_date_of_birth.birth_date 97 + "\n"); 98 } else { 99 System.out.print(" Date of birth is unknown.\n"); 100 } 101 102} 103} 104 105 static void birthday(int year,int month,int day){ 106 System.out.print("Date of Birth: " + this.year 107 + " " + this.month 108 + " " + this.day + "\n"); 109} 110 111 112 113 114} 115 116
(実行結果)
ex6_2.java:26: エラー: class、interfaceまたはenumがありません
public int year;
^
ex6_2.java:27: エラー: class、interfaceまたはenumがありません
public int month;
^
ex6_2.java:28: エラー: class、interfaceまたはenumがありません
public int day;
^
エラー3個
回答3件
あなたの回答
tips
プレビュー