Question: javakeywords - Notepad File Edit Format View Help abstract assert boolean break byte case catch char class const default do double else enum extends false

 javakeywords - Notepad File Edit Format View Help abstract assert booleanbreak byte case catch char class const default do double else enumextends false final finally float for goto if implements import instanceof intinterface long native new null package private protected public return short static

javakeywords - Notepad File Edit Format View Help abstract assert boolean break byte case catch char class const default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while continue Listing 1-1 A Java interface for a class of bags 1 2 3 4 5 6 7 8 9 10 An interface that describes the operations of a bag of objects. @author Frank M. Carrano, Timothy M. Henry public interface BagInterface /** Gets the current number of entries in this bag. @return The integer number of entries currently in the bag. */ public int getCurrentSize(); Sees whether this bag is empty. @return True if the bag is empty, or false if not. */ public boolean is Empty(); 12 13 14 15 16 17 18 19 /** Adds a new entry to this bag. @param newEntry The object to be added as a new entry. @return True if the addition is successful, or false if not. +/ public boolean add (T newEntry); /** Removes one unspecified entry from this bag, if possible. @return Either the removed entry, if the removal was successful, or null. */ public Tremove(); /** Removes one occurrence of a given entry from this bag, if possible. @param anEntry The entry to be removed. @return True if the removal was successful, or false if not. +/ public boolean remove (T anEntry); /** Removes all entries from this bag. */ public void clear(); 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /** Counts the number of times a given entry appears in this bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in the bag. */ public int get Frequencyof(T anEntry); /** Tests whether this bag contains a given entry. @param anEntry The entry to find. @return True if the bag contains anEntry, or false if not. */ public boolean contains (T anEntry); /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in the bag. Note: If the bag is empty, the returned array is empty. */ public TutoArray(); } // end BagInterface Listing 2-1 An outline of the class ArrayBag /** A class of bags whose entries are stored in a fixed-size array. */ public final class ArrayBag implements BagInterface private final T[] bag; private int number of Entries; private static final int DEFAULT_CAPACITY = 25; /** Creates an empty bag whose initial capacity is 25. */ public ArrayBag () this (DEFAULT_CAPACITY); } // end de fault constructor NOWOJOWNO OWN NNNNNNNNNPPPPPPP La Pop m ta po my ta /** Creates an empty bag having a given initial capacity. @param desiredcapacity The integer capacity desired. */ public ArrayBag (int desiredCapacity) // The cast is safe because the new array contains null entries. @SuppressWarnings ("unchecked") T[] tempBag = (T[])new Object[desired Capacity]; // Unchecked cast bag = tempBag; numberofEntries = 0; } // end constructor 29 /** Adds a new entry to this bag. @param newEntry The object to be added as a new entry. @return True if the addition is successful, or false if not. +/ public boolean add (T newEntry) { } // end add /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in the bag. */ public T[] toArray ( ) } // end toArray // Returns true if the ArrayBag is full, or false if not. private boolean isArrayFull() } // end isArrayFull 47 /** Gets the current number of entries in this bag. @return The integer number of entries currently in the bag. */ public int getCurrentSize(); Sees whether this bag is empty. @return True if the bag is empty, or false if not. */ public boolean is Empty(); 12 13 14 15 16 17 18 19 /** Adds a new entry to this bag. @param newEntry The object to be added as a new entry. @return True if the addition is successful, or false if not. +/ public boolean add (T newEntry); /** Removes one unspecified entry from this bag, if possible. @return Either the removed entry, if the removal was successful, or null. */ public Tremove(); /** Removes one occurrence of a given entry from this bag, if possible. @param anEntry The entry to be removed. @return True if the removal was successful, or false if not. +/ public boolean remove (T anEntry); /** Removes all entries from this bag. */ public void clear(); 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /** Counts the number of times a given entry appears in this bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in the bag. */ public int get Frequencyof(T anEntry); /** Tests whether this bag contains a given entry. @param anEntry The entry to find. @return True if the bag contains anEntry, or false if not. */ public boolean contains (T anEntry); /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in the bag. Note: If the bag is empty, the returned array is empty. */ public TutoArray(); } // end BagInterface Listing 2-1 An outline of the class ArrayBag /** A class of bags whose entries are stored in a fixed-size array. */ public final class ArrayBag implements BagInterface private final T[] bag; private int number of Entries; private static final int DEFAULT_CAPACITY = 25; /** Creates an empty bag whose initial capacity is 25. */ public ArrayBag () this (DEFAULT_CAPACITY); } // end de fault constructor NOWOJOWNO OWN NNNNNNNNNPPPPPPP La Pop m ta po my ta /** Creates an empty bag having a given initial capacity. @param desiredcapacity The integer capacity desired. */ public ArrayBag (int desiredCapacity) // The cast is safe because the new array contains null entries. @SuppressWarnings ("unchecked") T[] tempBag = (T[])new Object[desired Capacity]; // Unchecked cast bag = tempBag; numberofEntries = 0; } // end constructor 29 /** Adds a new entry to this bag. @param newEntry The object to be added as a new entry. @return True if the addition is successful, or false if not. +/ public boolean add (T newEntry) { } // end add /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in the bag. */ public T[] toArray ( ) } // end toArray // Returns true if the ArrayBag is full, or false if not. private boolean isArrayFull() } // end isArrayFull 47

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!