/* * MeasurableProduct.java * * Created on October 10, 2002, 1:58 PM */ package SimpleInherit; import SortSearchEtc.*; import IO.*; /** * * @author mike */ public class MeasurableProduct extends Product implements Comparable { private double quantity = -9; private String units = "fluid oz"; /** Creates a new instance of MeasurableProduct */ public MeasurableProduct() { } /** Creates a new instance of MeasurableProduct */ public MeasurableProduct(double amt) { quantity = amt; // others get defaults } /** Creates a new instance of MeasurableProduct */ public MeasurableProduct(double amt, String un) { // default constructor for Product runs quantity = amt; units = un; // others get defaults } /** Creates a new instance of MeasurableProduct */ public MeasurableProduct(String name, double price, double amt, String un) { super(name,price); quantity = amt; units = un; // id gets randomly gererated } /** Creates a new instance of MeasurableProduct */ public MeasurableProduct(String id, String name, double price, double amt, String un) { super(id, name, price); quantity = amt; units = un; } /////////////////////////////////////////////////////////////////////////// // inspectors /////////////////////////////////////////////////////////////////////////// /** * reports Product size */ public double getQuantity() { return quantity; } /** * reports Product units */ public String getUnits() { return units; } /** * give a user friendly view of contents of the product */ public String toString() { String res = super.toString(); res = res + " Size: " + quantity + " " + units + " Unit Price: " + calcUnitPrice() + " per " + units; return res; } /////////////////////////////////////////////////////////////// // Mutators /////////////////////////////////////////////////////////////// /** * change size of product package */ public void setQuantity (double amt) { if (amt <= 0.00) { System.out.println("ERROR - invalid quantity"); } else { quantity = amt; } } /** * change units for size of product package */ public void setUnits (String un) { units = un; } /** * @param args the command line arguments */ public static void main(String[] args) { System.exit(0); } }