Page 1 of 1

Implement in Java: Design and implement a one-person guessing game that chooses n random integers in the range from 1 to

Posted: Sun Jul 03, 2022 11:22 am
by answerhappygod
Implement in Java:
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 the range from 1 to 10that have been selected: 1 2 3 4
2 of your guesses are correct. Guess again.
Enter your guesses for the 4 integers in the range from 1 to 10that have been selected: 2 4 6 8
2 of your guesses are correct. Guess again.
1 4 6 6 You are correct!
Play again? No
Good-bye!
Design the game as an ADT. Use a bag to contain the integerschosen by the game. The integers m and n are specified by theclient.
You will write the "LinkedBag" class, and a main program named"Project1.java" testing the methods defined for the LinkedBagobject. This is the Bag Interface:
/**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 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 isEmpty();/** 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, ifpossible.@return Either the removed entry, if the removal.was successful, or null. */public T remove();/** Removes one occurrence of a given entry from this bag.@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();/** Counts the number of times a given entry appears in thisbag.@param anEntry The entry to be counted.@return The number of times anEntry appears in the bag. */public int getFrequencyOf(T anEntry);/** Tests whether this bag contains a given entry.@param anEntry The entry to locate.@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 thebag.Note: If the 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 the contents of this bag andanotherBag.@param anotherBag The bag that is to be added.@return A combined bag. */// public BagInterface<T> union(BagInterface<T>anotherBag);
/** Creates a new bag that contains those objects thatoccurin both this bag and anotherBag.@param anotherBag The bag that is to be compared.@return A combined bag. */// public BagInterface<T> intersection(BagInterface<T>anotherBag);
/** Creates a new bag of objects that would be left in thisbagafter removing those that also occur in anotherBag.@param anotherBag The bag that is to be removed.@return A combined bag. */// public BagInterface<T> difference(BagInterface<T>anotherBag);} // end BagInterface