/* Summary Info: Design a storage tank and fill it up Programmer: Kathy Piggford Date Due: 4/18/2014 Date Completed: 4//14 */ public class StorageTank { //declare private variables private double length; private double width; private double height; private double capacity; private double currentGallons; private boolean isAdd; private boolean isRemove; public StorageTank() { //create default constructor length = 0.0; width = 0.0; height = 0.0; capacity = 0.0; } //create new length, width, and height for default constructor public double getLength() { return length; } public void setLength(double newLength) { length = newLength; } public double getwidth() { return width; } public void setWidth(double newWidth) { width = newWidth; } public double getHeight() { return height; } public void setHeight(double newHeight) { height = newHeight; } //create overloaded constructor public StorageTank(double newLength, double newWidth, double newHeight) { this.length = newLength; this.width = newWidth; this.height = newHeight; } //create conversion constant public static final double CONVERTER = 7.48; //calculate the total capacity of the tank double getCapacity() { return (length * width * height) * CONVERTER; } private void setCapacity(double volume) { this.capacity = capacity; capacity = volume; } //keep track of current gallons private void setCurrentGallons(double volume) { this.currentGallons = currentGallons; currentGallons = volume; } public double getCurrentGallons() { return currentGallons; } //boolean value to check if adding more gallons will cause overflow public boolean add(double gallons) { if (gallons < 0.0) isAdd = false; double overflow = (gallons + currentGallons) - capacity; if (overflow > 0.0) isAdd = false; else currentGallons += gallons; System.out.println("Current add gallons is " + currentGallons); return isAdd; } //boolean value to check if removing gallons will cause underflow public boolean remove(double gallons) { if (gallons < 0.0) isRemove = false; double underflow = gallons - currentGallons; if (underflow > 0.0) isRemove = false; else currentGallons -= gallons; System.out.println("Current remove gallons is " + currentGallons); return isRemove; } //calculate the percent full of the tank double getPercentFull() { return (currentGallons / capacity) * 100; } }