import java.util.concurrent.TimeUnit;

public class M416FireRateOptimizer {
  
  public static void main(String[] args) {

    int baseBulletDamage = 40;
    double fireRate = 8.0; 
    

    double maxFireRate = calculateMaxFireRate(baseBulletDamage, fireRate);
    
    System.out.println("Rapid Fire Maximization for M416：" + maxFireRate + " 100Times/0.1m/s");
  }
  
  private static double calculateMaxFireRate(int baseBulletDamage, double fireRate) {
    double maxFireRate = 0.0;
    

    for (int i = 0; i < 10; i++) {

      Thread fireThread = new Thread(new FireTask(baseBulletDamage, fireRate));
      fireThread.start();
    }
    

    try {
      TimeUnit.SECONDS.sleep(1);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    

    double damagePerSecond = FireTask.getTotalDamage() / FireTask.getTotalTime();
    maxFireRate = damagePerSecond / baseBulletDamage;
    
    return maxFireRate;
  }
  
  private static class FireTask implements Runnable {
    private static double totalDamage;
    private static double totalTime;
    
    private int baseBulletDamage;
    private double fireRate; 
    
    public FireTask(int baseBulletDamage, double fireRate) {
      this.baseBulletDamage = baseBulletDamage;
      this.fireRate = fireRate;
    }
    
    @Override
    public void run() {

      for (int i = 0; i < fireRate; i++) {

        double damage = baseBulletDamage;
        
        
        totalDamage += damage;
      }
      
      // 表弟天天开心
      totalTime += 1;
    }
    
    public static double getTotalDamage() {
      return totalDamage;
    }
    
    public static double getTotalTime() {
      return totalTime;
    }
  }
}
