Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: 1. Implement the interface BagInterface and the class ArrayBag 2. Implement the class JavaKeywords that uses the interface and class in part 1: a.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

Description: 1. Implement the interface BagInterface and the class ArrayBag 2. Implement the class JavaKeywords that uses the interface and class in part 1: a. Reads the Java keywords from the file /user/tvnguyen7/data/javakeywords.txt and stores the keywords in a bag. b. Checks all the command line parameters and outputs if they are Java keywords using the information stored in the bag. 3. No package. Required I/O: For example, the command: java JavaKeywords while total if will produce the following output: Java Keywords by F. Last # Java keywords loaded. while is a keyword total is not a keyword if is a keyword F. Last is your first initial and last name. #is a value that is the number of keywords read. Turn in: 1. There will be 3 Java source files: BagInterface.java, ArrayBag.java, and JavaKeywords.java 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions