まず、Personクラスにはフィールドは1個、メソッドは3個あります。
そして、setWeightメソッドを追加すると、以下のようになります。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Person {   int weight;   void eatCake(int g, int count) {     System.out.println(g + "gのケーキを"+ count +"個食べます");     weight = weight + g * count;   }   void printWeight() {     System.out.println(weight);   }   int getWeight() {     return weight;    }   void setWeight(int value) {       weight = value;   } } | 
 
		

最近のコメント