// taken from HtDP by Felleisen et al., page 25
// argument: For OO, LoD implies Guideline on Auxiliary Functions in the sense
// that if we minimize LoD violations we are pushed to follow the Guideline.
// According to HtDP: The guideline is the first and 
// most important guideline to programming.

class Ticket {
  Ticket(double p) {price = p;}
  double price;
  double profit(){ // LoD violations: local 0
                   // LoD violations: in control flow: 2
    return this.revenue() - this.cost();
    // think of it as (pure oo style):
    // this.revenue().subtract(this.cost());
  }
  double revenue(){ // LoD violations: 0
    return this.attendance() * price;
    // think of it as:
    // this.attendance().multiply(price);
  }
  double cost() { // LoD violations: 0
    return 180.0 + (0.4 * this.attendance());
  }
  double attendance(){ // LoD violations 2
    return (120 + ((5.00 - price) / 15) *10);
    // think of it as:
    // new Double(120).add((
    //  (new Double(5).subtract(price)).divide
    //                                  ^ violation
    //    (new Double(15))).multiply
    //                      ^ violation
    //       (new Double(10))) )
  }

  double profit2() { // LoD violations: local 1
                     // LoD violations: in control flow: 5
    return
      (this.attendance() * price)
      -
//    ^ violation
      (180 + (0.4 * this.attendance()));
  }
 static public void main(String args[]) throws Exception {
   Double d1 = new Double(1);
   Double d2 = new Double(1);
   Double d3 = d1 + d2; System.out.println(d3.doubleValue());
   Ticket t = new Ticket(5.0);
   System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2());
   t = new Ticket(4.50);
   System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2());
   t = new Ticket(4.85);
   System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2());
   t = new Ticket(5.50);
   System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2());
  }
}

