package Lect42Review; public class DigitalCamera extends Camera implements Battery { private static final int DEFAULT_MEMORY = 100; private static final int DEFAULT_MEMORY_PER_PHOTO = 1; private int totalMegs, megsPerPhoto, availableMegs; public DigitalCamera() { this(DEFAULT_MEMORY, DEFAULT_MEMORY_PER_PHOTO); } public DigitalCamera(int theTotalMegs, int theMegsPerPhoto) { totalMegs = theTotalMegs; maxPhotos = totalMegs/theMegsPerPhoto; availableShots = maxPhotos; megsPerPhoto = theMegsPerPhoto; availableMegs = totalMegs; remainingPower = 500.0; } public void takePicture() { if ((availableShots > 0) && (remainingPower >= 1.0)) { System.out.println("Taking digital picture"); availableShots--; availableMegs -= megsPerPhoto; remainingPower -= 1.0; } } public void displayPhoto(int number) { System.out.println("Displaying digital photo num " + number); remainingPower -= 2.0; } public String toString() { String result = ""; result += super.toString() + "\n"; result += "TotalMegs: " + totalMegs + "\n"; result += "MegsPerPhoto: " + megsPerPhoto + "\n"; result += "Available Megs: " + availableMegs; return result; } // Interface methods public String getBatteryType() { return "AA"; } public double getRemainingPower() { return remainingPower; } }