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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 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 mainprogram named "Project1.java" testing the methods definedfor the LinkedBag object. Linked Bag object is this:
/** 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply