Page 1 of 1

Design and implement a one-person guessing game that chooses n random integers in the range from 1 to m and asks the use

Posted: Sun Jul 03, 2022 10:00 am
by answerhappygod
Design and implement a one-person guessing game that chooses nrandom integers in the range from 1 to m and asks the user to guessthem. The same integer might be chosen more than once. For example,the game might choose the following four integers that range from 1to 10: 4, 6, 1, 6. The following interaction could occur betweenthe user and the game: Enter your guesses for the 4 integers in therange from 1 to 10 that have been selected: 1 2 3 4 2 of yourguesses are correct. Guess again. Enter your guesses for the 4integers in the range from 1 to 10 that have been selected: 2 4 6 82 of your guesses are correct. Guess again. 1 4 6 6 You arecorrect! Play again? No Good-bye! Design the game as an ADT. Use abag to contain the integers chosen by the game. The integers m andn are specified by the client. 2. Define a class ArraySet thatrepresents a set and implements the interface described in Segment1.21 of the previous chapter. Use the class ResizableArrayBag inyour implementation. Then write a program that adequatelydemonstrates your implementation. 3. Repeat the previous project,but use a resizable array instead of the class ResizableArrayBag.4. Define a class PileOfBooks that implements the interfacedescribed in Project 2 of the previous chapter. Use a resizablearray in your implementation. Then write a program that adequatelydemonstrates your implementation. 5. Define a class Ring thatimplements the interface described in Project 3 of the previouschapter. Use a resizable array in your implementation. Then write aprogram that adequately demonstrates your implementation. 6. Youcan use either a set or a bag to create a spell checker. The set orbag serves as a dictionary and contains a collection of correctlyspelled words. To see whether a word is spelled correctly, you seewhether it is contained in the dictionary. Use this scheme tocreate a spell checker for the words in an external file. Tosimplify your task, restrict your dictionary to a manageable size.7. Repeat the previous project to create a spell checker, butinstead place the words whose spelling you want to check into abag. The difference between the dictionary (the set or bagcontaining the correctly spelled words) and the bag of words to bechecked is a bag of incorrectly spelled words.
You will write the "LinkedBag" class, and a mainprogram named "Project1.java" testing the methods definedfor the LinkedBag object. "LinkedBag" is here:
/** An interface that describes the operations of a bag ofobjects. @author Frank M. Carrano @author Timothy M. Henry @version 4.0*/public interface BagInterface<T>{ /** Gets the current number of entries in thisbag. @return The integernumber of entries currently in the bag. */ public int getCurrentSize(); /** Sees whether this bag is empty. @return True if thebag is empty, or false if not. */ public boolean isEmpty(); /** Adds a new entry to this bag. @param newEntry The objectto be added as a new entry. @return True if the additionis successful, or false if not. */ public boolean add(T newEntry);
/** Removes one unspecified entry from thisbag, if possible. @return Either the removed entry,if the removal. wassuccessful, or null. */ public T remove(); /** Removes one occurrence of a given entry fromthis bag. @param anEntry The entry to beremoved. @return True if the removal wassuccessful, or false if not. */ public boolean remove(T anEntry); /** Removes all entries from this bag. */ public void clear(); /** Counts the number of times a given entryappears in this bag. @param anEntry Theentry to be counted. @return The number oftimes anEntry appears in the bag. */ public int getFrequencyOf(T anEntry); /** Tests whether this bag contains a givenentry. @param anEntry Theentry to locate. @return True if thebag contains anEntry, or false if not. */ public boolean contains(T anEntry); /** Retrieves all entries that are in thisbag. @return A newlyallocated array of all the entries in the bag. Note: Ifthe bag is empty, the returned array is empty. */ public T[] toArray();// public <T> T[] toArray(); //Alternate// public Object[] toArray(); // Alternate
/** Creates a new bag that combines thecontents of this bag and anotherBag. @param anotherBag The bagthat is to be added. @return A combined bag.*/// public BagInterface<T>union(BagInterface<T> anotherBag);
/** Creates a new bag that contains thoseobjects that occur in both this bag and anotherBag. @param anotherBag The bagthat is to be compared. @return A combined bag.*/// public BagInterface<T>intersection(BagInterface<T> anotherBag);
/** Creates a new bag of objects that wouldbe left in this bag after removing those that also occur inanotherBag. @param anotherBag The bagthat is to be removed. @return A combined bag.*/// public BagInterface<T>difference(BagInterface<T> anotherBag);} // end BagInterface