DemoCabinRental Code

DemoCabinRental.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
package democabinrental;
 
/**
 *
 * @author mark
 */
public class DemoCabinRental {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        CabinRental cabin1 = new CabinRental(1);
        CabinRental cabin4 = new CabinRental(4);
 
        HolidayCabinRental hcabin1 = new HolidayCabinRental(1);
        HolidayCabinRental hcabin4 = new HolidayCabinRental(4);
 
        System.out.println(String.format("Cabin %d: $%.2f", 
                cabin1.getCabinNumber(), cabin1.getRate()));
        System.out.println(String.format("Cabin %d: $%.2f", 
                cabin4.getCabinNumber(), cabin4.getRate()));
        System.out.println(String.format("Cabin %d: $%.2f", 
                hcabin1.getCabinNumber(), hcabin1.getRate()));
        System.out.println(String.format("Cabin %d: $%.2f", 
                hcabin4.getCabinNumber(), hcabin4.getRate()));
 
 
    }
 
}

CabinRental.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
package democabinrental;
 
/**
 *
 * @author mark
 */
public class CabinRental {
    private int CabinNumber;
    protected double Rate;
    final int CUTOFF = 4;
    final double LOWRATE = 950;
    final double HIGHRATE = 1100;
 
    public CabinRental(int num){
        CabinNumber = num;
        if(CabinNumber < CUTOFF)
            Rate = LOWRATE;
        else
            Rate = HIGHRATE;
    }
 
    public int getCabinNumber(){
        return CabinNumber;
    }
    public double getRate(){
        return Rate;
    }
}

HolidayCabinRental.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
package democabinrental;
 
/**
 *
 * @author mark
 */
public class HolidayCabinRental extends CabinRental {
    public HolidayCabinRental(int num){
        super(num);
        final int SURCHARGE = 150;
        Rate += SURCHARGE;
    }
}