Illustrates the use of arrays #Programming Code Examples #Java/J2EE/J2ME #Basic Java

/** Report on a round of golf at St. Andy?s.
 *
 *  Taken from Core Web Programming from
 *  Prentice Hall and Sun Microsystems Press,
 *  .
 *  © 2001 Marty Hall and Larry Brown;
 *  may be freely used or adapted.
 */

public class Golf {
  public static void main(String[] args) {
    int[] pars   = { 4,5,3,4,5,4,4,3,4 };
    int[] scores = { 5,6,3,4,5,3,2,4,3 };
    report(pars, scores);
  }

  /** Reports on a short round of golf. */

  public static void report(int[] pars, int[] scores) {
    for(int i=0; i<scores .length; i++) {
      int hole = i+1;
      int difference = scores[i] - pars[i];
      System.out.println("Hole " + hole + ": " +
                         diffToString(difference));
    }
  }

  /** Convert to English. */

  public static String diffToString(int diff) {
    String[] names = {"Eagle", "Birdie", "Par", "Bogey",
                      "Double Bogey", "Triple Bogey", "Bad"};
    // If diff is -2, return names[0], or "Eagle".
    int offset = 2;
    return(names[offset + diff]);
  }
}

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10219
Categories:Programming Code Examples, Java/J2EE/J2ME, Basic Java
Tags:Java/J2EE/J2MEBasic Java
Post Data:2017-01-02 16:04:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada