Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Pityu Szíviso
Added: Nov 28, 2018 8:11 PM
Views: 2
Tags: no tags
  1.     public void fight(Carrier carrier) {
  2.         int totalDamage = 0;
  3.         boolean destroyed = false;
  4.         for (Aircraft aircraft : this.carrier) {
  5.             totalDamage = totalDamage + aircraft.fight();
  6.         }
  7.         carrier.healthPoint -= totalDamage;
  8.         if (carrier.healthPoint - totalDamage > 0) {
  9.             destroyed = true;
  10.         } else{
  11.             destroyed = false;
  12.         }
  13.         System.out.println("Carrier 1 fighter jets F11 and F35 fired shots at Carrier 2." );
  14.         System.out.println(destroyed == true ? "Carrier 2 was destroyed" : "Carrier 2 has" +carrier.healthPoint + " healtpoints left");
  15.  
  16.     }
  17.