以前の質問と関係があるのですが、この状態だと最後にTabibitoのhpが130になってしまいます。
どうやったら、最後にTabibitoのhpを90で表示させることができるのでしょうか?
それとも他に何か良いやり方はありますか?
追記
以前の質問
Java
1package Hero; 2 3public class main { 4 5 public static void main(String[] args){ 6 7 Tabibito t = new Tabibito(); 8 9 10 11 System.out.println("旅人"+t.name+"は戦いを始めた"); 12 13 matango m1 = new matango(); 14 15 m1.attack(); 16 m1.attack(); 17 m1.attack(); 18 m1.attack(); 19 t.aid(); 20 } 21 22} 23package Hero; 24 25 26public class Tabibito { 27 28 String name; 29 int hp; 30 final int MAX_HP = 100; 31 int mp ; 32 final int MAX_MP = 100; 33 34 35 Tabibito(){ 36 this.hp = 100; 37 this.mp = 50; 38 this.name = "旅人"; 39 } 40 41 42 void name(){ 43 System.out.println("名前を入力してください"); 44 String input = new java.util.Scanner(System.in).nextLine(); 45 name = input; 46 } 47 48 void aid(){ 49 50 this.hp += 30; 51 System.out.println(this.hp); 52 } 53} 54package Hero; 55 56 57public class matango { 58 59 int hp; 60 final int MAX_HP = 50; 61 int mp; 62 final int MAX_MP = 10; 63 64 Tabibito t = new Tabibito(); 65 66 67 matango(){ 68 this.hp = 100; 69 this.mp = 50; 70 } 71 72 void attack(){ 73 System.out.println("毒キノコは"+t.name+"に攻撃した"); 74 t.hp -= 10; 75 System.out.println(t.name+"の体力は"+t.hp+"になった"); 76 } 77 78 79} 80 81
「以前の質問」にも記入しましたが、タグのRPGはゲームと関係ないので削除していただければと思います。