Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4185425

javac silently generates broken classfile in case of constant pool overflow

XMLWordPrintable

    • x86, sparc
    • solaris_2.5.1, windows_95

      ) + " items.");
      }

      // equals method not required

      // other methods
      public void addItem(GroceryItem stuff) {
      basket.addElement(stuff);
      }

      public void removeItem(GroceryItem stuff) {
      basket.removeElement(stuff);
      }

      public GroceryItem heaviestItem() {
      Enumeration list = getBasket();
      if(!list.hasMoreElements() ) {return null; }

      double maxWeight = 0;
      GroceryItem HeavyOne = (GroceryItem)list.nextElement();
      maxWeight = HeavyOne.getWeight();

      while(list.hasMoreElements() ) {
      GroceryItem stuff = (GroceryItem)list.nextElement();
      if(stuff.getWeight() > maxWeight) {
      maxWeight = stuff.getWeight();
      HeavyOne = stuff;
      }
      }

      return HeavyOne;
      }

      public boolean have(GroceryItem stuff) {
      return basket.contains(stuff);
      }

      public void packBags(){
      bagList = new Vector();
      Enumeration allItems = getBasket();
      GroceryBag bag = new GroceryBag();

      // put items into the bag
      while( !basket.isEmpty() ) {
      GroceryItem stuff = heaviestItem();

      if(stuff.getWeight() > GroceryBag.getMaxWeight() ) {
      // too heavy for bag
      bagList.addElement(stuff);
      }
      else if( !bag.addItem(stuff) ) {
      // doesn't fit in this bag, put bag in list and
      start another
      bagList.addElement(bag);
      bag = new GroceryBag();

      // item must be small enough to fit in an empty
      bag
      bag.addItem(stuff);
      }

      // stuff put somewhere, remove from list
      basket.removeElement(stuff);

      } // while basket not empty
      } // packBags method

      public void makePurchase() {
      printReceipt();
      packBags();
      printPackedItems( );
      }

      private void printReceipt() {
      // max length of each part
      int nameSize = 20;
      int numSize = 5; // xx.xx

      // print all the items, formatted neatly
      // keeping a total of the prices

      // format
      // - name part - up to 20
      // - separator - min of one space
      // - price - right justified, max assumed to be 99.99
      for(int count = 0; count < basket.size(); count++) {
      GroceryItem stuff =
      (GroceryItem)basket.elementAt(count);
      StringBuffer info = new StringBuffer(stuff.getName() );

      // truncate long names
      if(info.length() > nameSize) {
      info.setLength(nameSize);
      }

      // room to grow
      info.ensureCapacity(nameSize + numSize + 1);

      // pad to name width, with one extra space
      while( info.length() < nameSize + 1) {
      info.append(' ');
      }

      // add the price - assumed to be exact x.xx
      info.append(stuff.getPrice() );

      // add an extra zero if exact x.x
      if( ((int)(stuff.getPrice() + .005) * 100) % 10 == 0) {
      info.append("0");
      }

      // pad in the middle at nameSize spot to line up to
      width
      while( info.length() < nameSize + numSize + 1) {
      info.insert(nameSize, " ");
      }
      } // for
      } // printReceipt

      public void printPackedItems() {
      Enumeration packList = bagList.elements();
      SimpleIO o = new SimpleIO();

      o.outln("Packing list");
      o.outln("===================");

      while( packList.hasMoreElements() ) {
      Object thing = packList.nextElement();
      if(thing instanceof GroceryItem) {
      o.outln("\n- Unpacked item:");
      o.outln((GroceryItem)thing + "");
      }
      else {
      // must be a bag
      o.outln("\n- Bag containing:");
      GroceryBag bag = (GroceryBag)thing;
      o.outln(bag.toString() );

      Enumeration eBag = bag.getListOfItems();
      while(eBag.hasMoreElements() ) {
      o.outln(" " +
      ((GroceryItem)eBag.nextElement()).toString() );
      }
      }
      } // while
      } // printPackedItems

      public void unpackPerishables() {
      for (int count = 0; count < bagList.size(); count++ ) {
      if (bagList.elementAt(count) instanceof GroceryItem) {
      if (
      ((GroceryItem)bagList.elementAt(count)).getPerishable() ) {
      bagList.removeElementAt(count);
      }
      }
      else {
      // must be a bag
      GroceryBag bag =
      (GroceryBag)bagList.elementAt(count);
      Enumeration eBag = bag.getListOfItems();
      while (eBag.hasMoreElements() ) {
      GroceryItem stuff =
      (GroceryItem)eBag.nextElement();
      if ( stuff.getPerishable() ) {
      bag.removeItem(stuff);
      }
      }// while
      if(bag.size() == 0 ) {
      bagList.remove(bagList.elementAt(count)
      );
      count--; // now points at the most
      recently evaluated item
      // bagList.size has just been
      reduced also
      }
      } // else
      } // for
      } // unpackPerishables

      } // Customer class
      -------------------------------
      import java.util.*;

      public class GroceryBag {
      // class variables
      private static double maxWeight = 5;

      // class methods
      public static double getMaxWeight() { return maxWeight; }

      // instance variables
      private Vector listOfItems;
      private double totalWeight;

      // get methods
      public double getTotalWeight() { return totalWeight; }
      public int size() { return listOfItems.size(); }

      // public Vector getListOfItems() { return listOfItems; }
      // returning an enumeration will allow the class
      // to retain control, through its methods, of the contents
      // of the bag. For instance, if items are removed only through
      // removeItem, then the totalWeight variable should be accurate
      // - OK, the enumeration bit me. So I return an enumeration of a copy.
      // *** NOTE: I considered iterators, but did not use them because they
      // allow removal of an item from the underlying class
      // - same flaw as for returning the Vector itself
      public Enumeration getListOfItems() {
      Vector copy = (Vector)listOfItems.clone();
      Enumeration list = copy .elements();
      return list;
      }

      // set methods
      // I think no one outside the class should "correct"
      // the total weight and the listOfItems
      // - only addItem and removeItem should affect it
      private boolean setTotalWeight(double newWeight) {
      if(newWeight >= 0 && newWeight <= 5.0) {
      totalWeight = newWeight;
      return true;
      }
      else {
      return false;
      }
      }

      // constructor
      public GroceryBag () {
      maxWeight = 0.0;
      listOfItems = new Vector();
      }

      // standard methods
      public String toString () {
      if( listOfItems.isEmpty() ) {
      return "The bag is empty";
      }
      return("There are " + listOfItems.size() +
      " items in this bag, weighing a total of " +
      totalWeight + " kg." );
      }

      // "equals" method not required, since the Customer methods
      // do not compare items in the vector (packBags and unpackPerishables)
      // this could be added later if required.

      // other methods

      // returns true if the item is put successfully in the bag
      // this means we can check weight here rather than in the calling
      program
      public boolean addItem (GroceryItem itemToPack) {
      boolean weightOK = setTotalWeight(totalWeight +
      itemToPack.getWeight());
      if (weightOK) { listOfItems.addElement(itemToPack); }
      return weightOK;
      }

      // we could overload this class to remove a specified
      // item. This would allow us to do the unpackPerishable
      // method totally through class methods, and then
      // getListOfItems could return an enumeration, rather than
      // the original vector.
      public void removeItem() {
      setTotalWeight( totalWeight -
      ((GroceryItem)(listOfItems.lastElement()
      )).getWeight() );
      listOfItems.removeElementAt( listOfItems.size() - 1 );
      }

      public void removeItem(GroceryItem stuff) {
      if( !listOfItems.contains(stuff)) { return; }

      setTotalWeight( totalWeight - stuff.getWeight() );

      listOfItems.removeElement(stuff);
      }
      }
      -----------------------
      import java.util.*;

      public class GroceryItem {
      // instance variables
      private String name = "";
      private double price = 0;
      private double weight = 0;
      private boolean perishable = true;

      // get methods
      public String getName() { return name; }
      public double getPrice() { return price; }
      public double getWeight() { return weight; }
      public boolean getPerishable() { return perishable; }

      // set methods
      protected void setName(String aName) {
      name = aName;
      }

      protected void setPrice(double aPrice) {
      if( aPrice > 0 ) {
      price = aPrice;
      }
      else {
      SimpleIO o = new SimpleIO();
      o.log("Invalid price: " + aPrice + "\n Price not
      changed.");
      }
      }

      protected void setWeight(double aWeight) {
      if( aWeight > 0 ) {
      weight = aWeight;
      }
      else {
      SimpleIO o = new SimpleIO();
      o.log("Invalid Weight: " + aWeight+ "\n Weight not
      changed.");
      }
      }

      protected void setPerishable(boolean isPerishable) {
      perishable = isPerishable;
      }

      // constructors
      public GroceryItem() {
      name = "New Grocery Item";
      price = 0.0;
      weight = 0.0;
      perishable = false;
      }

      public GroceryItem(
      String aName,
      double aPrice,
      double aWeight)
      {
      setName(aName);
      setPrice(aPrice);
      setWeight(aWeight);
      }
      public GroceryItem(
      String aName,
      double aPrice,
      double aWeight,
      boolean isPerishable)
      {
      this(aName, aPrice, aWeight);
      perishable = isPerishable;
      }

      // standard methods
      public String toString() {
      return( name + " at " + price + " weighing " + weight + "kg.");
      }

      public boolean equals(Object stuff) {
      if(!(stuff instanceof GroceryItem)) { return false; }

      GroceryItem item = (GroceryItem)stuff;

      return( item.getName() == name &&
      item.getPrice() == price &&
      item.getWeight() == weight
      );
      }





      }
      (Review ID: 98113)
      ======================================================================


      Name: laC46010 Date: 10/29/98


         Compiler generates broken classfile from source file which contains 32768 'double'
      or 'long' literals. VM can not load such classfile and throws ClassFormatError:
      (Invalid constant pool entry). If class contains 32744 'double' literals compiler
      generates correct classfile. This bug also exists in 1.1.x compiler versions.
      If compiler uses two entries in constant pool for 'double' literal it should check for 65536
      entries limit overflow and report a proper error message.

      The following template generates the test which contains 32768 'double' literals
      ------------------------------------------------------------

      cat test1.java
      class test1 {

         static int ARRAY_N = 8; /* Array number */
         static int CPA = 4096; /* Constants per array */
         static int CPL = 10; /* Constants per line */
         static String TYPE = "double";
         static String TS = ".0";
         public static void main(String[] argv) {
            int TOTAL = 0;
            System.out.print("import java.io.PrintStream;\n\n");
            System.out.print( "class test {\n\n");
            for (int i = 0; i < ARRAY_N; ++i) {
               int COUNT = 0;
               System.out.print(" static "+TYPE+"[] arr"+i+";\n");
               System.out.print(" static void m"+i+"() {\n");
               System.out.print(" arr"+i+" = new "+TYPE+"[] {\n");
               for (int l = 0; l <= CPA/CPL; l++) {
                  String const_line = " ";
                  for (int j = 0; (j < CPL) && (COUNT++ < CPA); j++)
                    const_line = const_line + (j==0 && l==0 ? "":",") + TOTAL++ + TS;
                  System.out.println(const_line);
               }
               System.out.print(" };\n }\n");
            }
            System.out.println(" public static void main(String args[]) {\n System.out.println(\"Ok\"); }");
            System.out.println("}");
         }
      }

      novo35% java -version
      java version "1.2fcs"
      Classic VM (build JDK-1.2fcs-M, green threads, sunwjit)
      novo35% javac test1.java
      novo35% java test1 > test.java
      novo35% javac test.java
      novo35% java -verify test
      Exception in thread "main" java.lang.ClassFormatError: test (Invalid constant pool entry)
              at java.lang.ClassLoader.defineClass0(Native Method)
              at java.lang.ClassLoader.defineClass(Compiled Code)
              at java.security.SecureClassLoader.defineClass(Compiled Code)
              at java.net.URLClassLoader.defineClass(Compiled Code)
              at java.net.URLClassLoader.access$1(Compiled Code)
              at java.net.URLClassLoader$1.run(Compiled Code)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(Compiled Code)
              at java.lang.ClassLoader.loadClass(Compiled Code)
              at sun.misc.Launcher$AppClassLoader.loadClass(Compiled Code)
              at java.lang.ClassLoader.loadClass(Compiled Code)

      -------------------------------------------------------

      ======================================================================

      Name: krT82822 Date: 11/21/99


      (see also 4185425, 4210137)

      D:\data\ECHLIN\Rme\courses\ass4>java -version
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)


      java.lang.ClassFormatError: java/util/Arrays (Illegal constant pool type)
      at java.lang.ClassLoader.findBootstrapClass(Native Method)
      at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
      at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java, Compiled
      Code)
      at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
      at sun.tools.javac.SourceClass.compileClass(SourceClass.java:2220)
      at sun.tools.javac.SourceClass.compile(SourceClass.java:2039)
      at sun.tools.javac.Main.compile(Main.java:567)
      at sun.tools.javac.Main.main(Main.java:733)
      error: An error has occurred in the compiler; please file a bug report
      (http://java.sun.com/cgi-bin/bugreport.cgi).
      1 error
      Process completed with exit code 4

      --------------------------
      The code follows:
      It is for a university class in OOP with Java.
      I have been able to compile and run it until I made the latest corrections.

      --------------------------
      import java.util.*;

      public class SuperMarket {
      public static void main(String[] argv) {
      // testGroceryItem();
      testGroceryBag();
      testCustomerBasic();
      testNoItems();
      testOneItem();
      testTwoItems();
      testOneBag();
      testOneBagEach();
      testNoneFits();
      testMiddleTooBig();
      }

      // some items
      private static GroceryItem cheese() {
      return new GroceryItem( "cheese", 2.34, .4);
      }

      private static GroceryItem bigCheese() {
      return new GroceryItem( "Big cheese", 2.34, .4);
      }

      private static GroceryItem milk() {
      return new GroceryItem( "milk ", 3.29, 4.0);
      }

      private static GroceryItem eggs() {
      return new GroceryItem( "eggs ", 2.49, .6);
      }

      private static GroceryItem coke() {
      return new GroceryItem( "case of coke ", 5.99, 7.2, false);
      }

      private static GroceryItem pork_chops() {
      return new GroceryItem( "pork chops", 9.1, 1.5);
      }

      private static GroceryItem spaghetti() {
      return new GroceryItem( "spaghetti", .99, .9, false);
      }

      private static GroceryItem potatoes() {
      return new GroceryItem( "bag of potatoes", 2.29, 10, false);
      }

      private static GroceryItem oranges() {
      return new GroceryItem( "cello of oranges", 3.57, 4.6);
      }

      private static GroceryItem bread() {
      return new GroceryItem( "bread", 1.69, .454);
      }

      private static GroceryItem grapefruit() {
      return new GroceryItem( "carton of grapefruit", 3.96, 4.7);
      }

      private static GroceryItem bananas() {
      return new GroceryItem( "bananas", 2.54, 3.6);
      }

      private static GroceryItem tide() {
      return new GroceryItem( "Tide", 8.99, 5.6);
      }

      private static GroceryItem kleenex() {
      return new GroceryItem( "Kleenex", .99, .45);
      }

      // tests for each individual class
      public static void testGroceryItem() {
      SimpleIO o = new SimpleIO();

      o.outln("*** Testing GroceryItem class");

      o.outln("\n* Test simple constructor with toString");
      GroceryItem gNone = new GroceryItem();
      o.outln(gNone.toString() );
      o.outln("Is it perishable? " + gNone.getPerishable() );

      o.outln("\n* Setting name, price, weight, perishable");
      gNone.setName("Zero");
      gNone.setPrice(1.95);
      gNone.setWeight(3.25);
      gNone.setPerishable(true);
      o.outln(gNone.toString() );
      o.outln("Is it perishable? " + gNone.getPerishable() );
      o.outln("Make it non-perishable");
      gNone.setPerishable(false);
      o.outln("Is it perishable now? " + gNone.getPerishable() );

      o.outln("\n* Test normal constructor - call it gReg");
      GroceryItem gReg = new GroceryItem("Ivory", 0.99, 0.2);
      o.outln(gReg.toString() );

      o.outln("\n* Test other get methods on gReg");
      o.outln(" Name: " + gReg.getName() );
      o.outln(" Price: " + gReg.getPrice() );
      o.outln(" Weight: " + gReg.getWeight() );

      o.outln("\n* Make another one just like gReg - call it gTwo");
      GroceryItem gTwo = new GroceryItem("Ivory", 0.99, 0.2);
      o.outln(gTwo.toString() );
      o.outln("Is gReg Perishable? " + gReg.getPerishable() );
      o.outln("Is gTwo Perishable? " + gTwo.getPerishable() );
      o.outln("Are they equal? " + gTwo.equals(gReg) );

      o.outln("\n* Make gTwo non-perishable");
      gTwo.setPerishable(false);
      o.outln("Is gReg Perishable? " + gReg.getPerishable() );
      o.outln("Is gTwo Perishable? " + gTwo.getPerishable() );
      o.outln("Are they equal? " + gTwo.equals(gReg) );

      o.outln("\n* Make gTwo a different weight");
      gTwo.setPerishable(false);
      gTwo.setWeight(0.5);
      o.outln(gReg.toString() );
      o.outln(gTwo.toString() );
      o.outln("Are they equal? " + gTwo.equals(gReg) );

      o.outln("\n* Make gTwo a different price");
      gTwo.setWeight(0.5);
      gReg.setWeight(0.5);
      gTwo.setPrice(0.5);
      o.outln(gReg.toString() );
      o.outln(gTwo.toString() );
      o.outln("Are they equal? " + gTwo.equals(gReg) );

      o.outln("\n* Make gTwo a different name");
      gReg.setPrice(0.99);
      gTwo.setPrice(0.99);
      gTwo.setName("Plus");
      o.outln(gReg.toString() );
      o.outln(gTwo.toString() );
      o.outln("Are they equal? " + gTwo.equals(gReg) );
      }

      public static void testGroceryBag() {
      SimpleIO o = new SimpleIO();

      o.outln("******************************");
      o.outln("\n*** Test GroceryBag class");

      o.outln("\n* Test constructor, toString");
      GroceryBag bag1 = new GroceryBag();
      o.outln(bag1.toString() );

      o.outln("\n* Test addItem, toString");
      bag1.addItem(cheese() );
      o.outln(bag1.toString() );
      bag1.addItem(bread() );
      o.outln(bag1.toString() );
      bag1.addItem(eggs() );
      o.outln(bag1.toString() );
      bag1.addItem(spaghetti() );
      o.outln(bag1.toString() );

      o.outln("\n* Test removeItem()");
      bag1.removeItem();
      o.outln(bag1.toString() );

      o.outln("\n* Test getListOfItems, removeItem(item)");
      Enumeration eBag = bag1.getListOfItems();
      while (eBag.hasMoreElements() ) {
      bag1.removeItem((GroceryItem)eBag.nextElement() );
      o.outln(bag1.toString() );
      }
      }

      public static void testCustomerBasic() {
      SimpleIO o = new SimpleIO();

      o.outln("\n\n******************************");
      o.outln("\n*** Test Customer class");

      o.outln("\n* Test simple constructor, toString");

      Customer guy = new Customer();
      o.outln(guy.toString() );

      o.outln("\n* Test name constructor");

      Customer george = new Customer("George");
      o.outln(george.toString() );

      o.outln("\n* Test getName ");
      o.outln("Name: " + george.getName() );
      }

      public static void testNoItems() {
      SimpleIO o = new SimpleIO();
      Customer george = new Customer("George");

      o.outln("\n* Test printReceipt, heaviestItem, packbags, with no
      items ");
      o.outln("Heaviest Item: " + george.heaviestItem() );
      george.printReceipt();
      george.packBags();
      george.printPackedItems();
      }

      public static void testOneItem() {
      SimpleIO o = new SimpleIO();
      Customer george = new Customer("George");

      o.outln("\n* Test addItem ");
      george.addItem(bananas() );
      Enumeration oneItem = george.getBasket();
      while (oneItem.hasMoreElements() ) {
      o.outln( ((GroceryItem)oneItem.nextElement()).toString()
      );
      }

      o.outln("\n* Test heaviestItem, packbags, makePurchase with one
      item ");
      o.outln("Heaviest Item: " + george.heaviestItem() );
      george.packBags();
      george.printPackedItems();

      o.outln("\nMake Purchase: ");
      george.makePurchase();

      }

      public static void testTwoItems() {
      SimpleIO o = new SimpleIO();
      Customer fred = new Customer("Fred");

      o.outln("\n* Test with two items ");
      fred.addItem(oranges() );
      fred.addItem(kleenex() );
      o.outln("\nMake Purchase: ");
      fred.makePurchase();
      }

      public static void testOneBag() {
      SimpleIO o = new SimpleIO();
      Customer frank = new Customer("Frank");

      o.outln("\n* Test with several items that fit into one bag,
      including duplicates ");
      frank .addItem(cheese() );
      frank .addItem(cheese() );
      frank .addItem(cheese() );
      frank .addItem(cheese() );
      frank .addItem(kleenex() );
      frank .addItem(kleenex() );
      frank .addItem(eggs() );
      o.outln("\nMake Purchase: ");
      frank .makePurchase();
      }

      public static void testOneBagEach() {
      SimpleIO o = new SimpleIO();
      Customer ellen = new Customer("Ellen");

      o.outln("\n* Test with several items that fit into one bag each,
      including duplicates ");
      ellen.addItem(oranges() );
      ellen.addItem(milk() );
      ellen.addItem(milk() );
      ellen.addItem(bananas() );
      ellen.addItem(grapefruit() );
      ellen.makePurchase();
      }

      public static void testNoneFits() {
      SimpleIO o = new SimpleIO();
      Customer doug = new Customer("Doug");

      o.outln("\n* Test with several items that don't fit into bags,
      including duplicates ");
      doug.addItem(coke() );
      doug.addItem(potatoes() );
      doug.addItem(tide() );
      doug.addItem(tide() );
      doug.addItem(coke() );
      doug.makePurchase();
      }

      public static void testMiddleTooBig() {
      SimpleIO o = new SimpleIO();
      Customer carl = new Customer("Carl");

      o.outln("\n* Test with several items and the middle one is too
      big for a bag");
      carl.addItem(spaghetti() );
      carl.addItem(kleenex() );
      carl.addItem(kleenex() );
      carl.addItem(coke() );
      carl.addItem(pork_chops() );
      carl.addItem(bananas() );
      carl.addItem(kleenex() );
      carl.addItem(kleenex() );
      carl.addItem(kleenex() );
      carl.addItem(potatoes() );
      carl.addItem(kleenex() );
      carl.addItem(milk() );
      carl.addItem(eggs() );
      carl.addItem(kleenex() );
      carl.makePurchase();
      }

      public static void testPerishables() {
      SimpleIO o = new SimpleIO();
      Customer bob = new Customer("Bob");

      o.outln("\n* Test unpacking of perishables - no perishables");
      bob.addItem(spaghetti() );
      bob.addItem(kleenex() );
      bob.addItem(kleenex() );
      bob.addItem(tide() );
      bob.makePurchase();
      o.outln("\n Unpacking perishables");
      bob.unpackPerishables();
      bob.printPackedItems();

      o.outln("\n* Test unpacking of perishables - some are
      perishables");
      Customer candi = new Customer("Candi");
      candi.addItem(cheese() );
      candi.addItem(spaghetti() );
      candi.addItem(kleenex() );
      candi.addItem(kleenex() );
      candi.addItem(tide() );
      candi.addItem(cheese() );
      candi.addItem(bigCheese() );
      candi.addItem(oranges() );
      candi.addItem(spaghetti() );
      candi.addItem(kleenex() );
      candi.addItem(kleenex() );
      candi.addItem(tide() );
      candi.addItem(bananas() );
      candi.addItem(eggs() );
      candi.addItem(eggs() );
      candi.addItem(spaghetti() );
      candi.addItem(bread() );
      candi.addItem(bread() );
      candi.addItem(grapefruit() );
      candi.addItem(spaghetti() );
      candi.addItem(pork_chops() );
      candi.addItem(milk() );
      candi.addItem(tide() );
      candi.makePurchase();
      o.outln("\n Unpacking perishables");
      candi.unpackPerishables();
      candi.printPackedItems();

      o.outln("\n* Test unpacking of perishables - all perishables");
      Customer don = new Customer("Don");
      don.addItem(cheese() );
      don.addItem(cheese() );
      don.addItem(bigCheese() );
      don.addItem(oranges() );
      don.addItem(bananas() );
      don.addItem(eggs() );
      don.addItem(eggs() );
      don.makePurchase();
      o.outln("\n Unpacking perishables");
      don.unpackPerishables();
      don.printPackedItems();

      o.outln("\n* Test final results after working with three
      customers at once");
      bob.printPackedItems();
      candi.printPackedItems();
      don.printPackedItems();
      }

      }
      -----------------------------------
      import java.util.*;

      public class Customer {
      // instance variables
      private String name = "";
      private Vector basket;
      private Vector bagList; // to hold the stuff after it is packed

      // get methods
      public String getName() { return name; }
      public Enumeration getBasket() {
      return basket.elements();
      }
      // no need to "get" bagList

      // set methods
      protected void setName(String aName) { name = aName; }

      // set method not appropriate for basket
      // bagList set by packBags method

      // constructor
      public Customer() {
      name = "No Name yet";
      basket = new Vector();
      }

      public Customer(String aName) {
      name = aName;
      basket = new Vector();
      }

      // Standard methods
      public String toString() {
      return( name + " with a basket of " +
      basket.size(

            wmaddoxsunw William Maddox (Inactive)
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: