Android Open Source - android-nfl-passer-rating Nfl Passer Rating






From Project

Back to project page android-nfl-passer-rating.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project android-nfl-passer-rating listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * This is free and unencumbered software released into the public domain.
 * /*from  ww  w . j a  v a 2  s  .  c o  m*/
 * Anyone is free to copy, modify, publish, use, compile, sell, or
 * distribute this software, either in source code form or as a compiled
 * binary, for any purpose, commercial or non-commercial, and by any
 * means.
 * 
 * In jurisdictions that recognize copyright laws, the author or authors
 * of this software dedicate any and all copyright interest in the
 * software to the public domain. We make this dedication for the benefit
 * of the public at large and to the detriment of our heirs and
 * successors. We intend this dedication to be an overt act of
 * relinquishment in perpetuity of all present and future rights to this
 * software under copyright law.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * For more information, please refer to <http://unlicense.org/>
 */


package com.github.pffy.sports;


/**
 * This object calculates the National Football League passer rating.
 * @author The Pffy Authors
 * 
 */
public class NflPasserRating extends AbstractPasserRating {

  public static void main(String[] args) {
    NflPasserRating nfl = new NflPasserRating(17, 20, 287, 5, 0);
    System.out.println(nfl);
  }

  /**
   * Builds this object.
   */
  public NflPasserRating() {}

  /**
   * Builds this object with all parameters.
   * 
   * @param completedPasses
   * @param attemptedPasses
   * @param yardsPassing
   * @param touchdownPasses
   * @param interceptedPasses
   */
  public NflPasserRating(double completedPasses, double attemptedPasses, double yardsPassing,
      double touchdownPasses, double interceptedPasses) {

    super();

    this.completedPasses = completedPasses;
    this.attemptedPasses = attemptedPasses;
    this.yardsPassing = yardsPassing;
    this.touchdownPasses = touchdownPasses;
    this.interceptedPasses = interceptedPasses;
  }
  
  /**
   * Returns the NFL passer rating.
   * 
   * @return rating NFL passer rating.
   * 
   */
  public double getRating() {
    double m = 0.0;
    try {
      m = (mm(a()) + mm(b()) + mm(c()) + mm(d())) / 0.06;
      return Math.round(m * 10.0) / 10.0;
    } catch (Exception e) {
      e.printStackTrace();
      return 0.0;
    }
  }

  /*
   * Returns the sub-rating component for pass completions
   * 
   * @throws Exception if attempted passes is equal to zero
   */
  private double a() throws Exception {
    return (((this.completedPasses / this.attemptedPasses) * 100) - 30) / 20;
  }


  /*
   * Returns the sub-rating component for yards passing
   * 
   * @throws Exception if attempted passes is equal to zero
   */
  private double b() throws Exception {
    return ((this.yardsPassing / this.attemptedPasses) - 3) / 4;
  }


  /*
   * Returns the sub-rating component for the touchdown passes
   * 
   * @throws Exception if attempted passes is equal to zero
   */
  private double c() throws Exception {
    return ((this.touchdownPasses / this.attemptedPasses) * 100) / 5;
  }

  
  /*
   * Returns the sub-rating component for intercepted passes
   * 
   * @throws Exception if attempted passes is equal to zero
   */
  private double d() throws Exception {
    return (9.5 - ((this.interceptedPasses / this.attemptedPasses) * 100)) / 4;
  }

  
  /*
   * Returns a sub-rating value bound between 0 and 2.375.
   * 
   * @throws Exception if attempted passes is equal to zero
   */
  private double mm(double subRating) {
    return Math.max(0, Math.min(subRating, 2.375));
  }
}




Java Source Code List

com.github.pffy.qbrating.PasserRatingActivity.java
com.github.pffy.sports.AbstractPasserRating.java
com.github.pffy.sports.AflPasserRating.java
com.github.pffy.sports.NcaaPasserRating.java
com.github.pffy.sports.NflPasserRating.java