ApexSensei

Drills Classes & objects

Expose a read-only quote total

Apex properties expose a value through get and set, and a getter-only property returns a derived value.

Your task

Finish the total getter and changeSubtotal, then print three totals.

class RenewalQuote {
    public Decimal subtotal { get; private set; }

    public Decimal total {
        get {
            return 0;
        }
    }

    public RenewalQuote(Decimal subtotal) {
        this.subtotal = subtotal;
    }

    public void changeSubtotal(Decimal newSubtotal) {
    }
}

Requirements

  1. Direct subtotal assignment should be absent
  2. changeSubtotal body should be present
  3. Total getter should be present
  4. Initial total should be Initial total: 108.00
  5. Updated total should be Updated total: 270.00
  6. Zero-subtotal total should be Zero subtotal: 0.00
  7. new RenewalQuote(19.99).total should be 21.59

Sign in to open this drill