For this project, you will use the bag of integers from Section 4.4. The bag includes the
Question:
For this project, you will use the bag of integers from Section 4.4. The bag includes the grab method from Figure 4.16 on page 229. Use this class in an applet that has three components:
1. A button
2. A small text field
3. A large text area
Each time the button is clicked, the applet should read an integer from the text field and put this integer in a bag. Then a random integer is grabbed from the bag, and a message is printed in the text area—something like “My favorite number is now ... .”
Transcribed Image Text:
FIGURE 4.16 Implementation of a Method to Grab a Random Element Implementation public int grab( ) int i; // A random value between 1 and the size of the bag IntNode cursor; if (manyNodes =- 0) throw new IllegalStateException("Bag size is zero."); 3%%3D (int) (Math.random( ) * manyNodes) + 1; cursor = IntNode.listPosition (head, i); return cursor.getData( ); }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 57% (7 reviews)
Here is a sample implementation of the applet in Java import javaawtFlowLayout import javaawteventAc...View the full answer
Answered By
Akshay Shete
I have extensive experience as a tutor, both online and in-person. I have worked with students of all ages and abilities, and am skilled at adapting my teaching style to meet the needs of each individual student. I have a strong background in a variety of subjects, including math, science, and English, and am able to break down complex concepts in a way that is easy for students to understand. In addition to my subject matter expertise, I am also a patient and supportive teacher, and am committed to helping my students succeed. Whether I am working with a struggling student who needs extra help to catch up, or an advanced student looking to get ahead, I am able to provide the guidance and support they need to reach their goals. Overall, my hands-on experience as a tutor has prepared me to be a confident and effective teacher, and I am excited to use my skills to help students succeed.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
A compare-exchange operation on two array elements A[i] and A[j], where i < j, has the form COMPARE-EXCHANGE (A, i, j) 1 If A[i] > A[j] 2 exchange A[i] with A[j] After the compare-exchange operation,...
-
For this project you are tasked with building a user application that will select sets of random numbers. Your application must use functions and pass values. Your program will pick sets of 6 random...
-
The Company Lalo Company, headquartered in Vaduz, is a company listed in Amsterdam, Paris and Zurich. It is the third largest small home appliance manufacturer in Europe. The company was founded in...
-
Attlee Ltd holds 28% of the issued shares of Nehru Ltd. Attlee Ltd acquired these shares on 1 July 2019 and on this date all the identifiable assets and liabilities of Nehru Ltd were recorded at...
-
Use the annual values for person-days lost in the truck-based transportation industry due to work stoppages. Find the percentile corresponding to the given number of person-days lost. 1000
-
Update the trial balance for Kreg?s Moving Co. (Figure 4.27 on page 137) for October 31, 201X. Adjustment Data to Update Trial Balance 1. Insurance expired, $550. 2. Moving supplies on hand, $800. 3....
-
P 2 Use the Standard Normal Table or technology to find the z-score that corresponds to the cumulative area or percentile. Table 4-Standard Normal Distribution Arca 0 z Z .09 .08 .07 .06 .05 .04 .03...
-
(Comprehensive Income) Roxanne Carter Corporation reported the following for 2004: net sales $1,200,000; cost of goods sold $750,000; selling and administrative expenses $320,000; and an unrealized...
-
Martinez Company's ending inventory includes the following items. Product Helmets Units Cost per Unit Market per Unit 33 $ 55 $ 51 Bats 26 73 79 Shoes 47 Uniforms 51 92 37 96 37 Compute the lower of...
-
State with brief reason whether the following statements are true, false, or uncertain: a. In the presence of heteroscedasticity OLS estimators are biased as well as inefficient. b. If...
-
Suppose that you want to implement a bag class to hold non-negative integers, and you know that the biggest number in the bag will never be more than a few thousand. One approach for implementing...
-
Write a new static method for the node class. The method has one parameter, which is a head node for a linked list of integers. The method computes a new linked list, which is the same as the...
-
Let R be a nonzero commutative ring, and let T be a nonempty subset of R closed under multiplication and containing neither 0 nor divisors of 0. Starting with R x T and otherwise exactly following...
-
What is the difference between in-store and out-of-store promotions? What are some of the most common types of vehicles and how can they be promoted and tied to an IMC campaign?
-
What are the strategic uses of sales promotion in an IMC campaign?
-
Location-based capabilities bring what additional advertising opportunities to the promotional mix?
-
When is Internet advertising best used in an IMC campaign?
-
Why is it important for the strategy employed elsewhere in the IMC campaign to remain consistent across multiple vehicles?
-
Justin Stone was an employee of Data Care Services, Inc. His salary was $45,000 through November 10, 2015, when he was laid off. Data Care Services provided medical insurance for Justin and his...
-
Two mutually exclusive investment alternatives are being considered. Alternative A requires an initial investment of $20,000 in a machine. Annual operating and maintenance costs are anticipated to be...
-
What are different operations we can perform on queues?
-
Why and when should we use stack and queue data structures instead of arrays or Lists?
-
Explain what are Infix, Prefix and Postfix Expressions?
-
What are some scholarly sources that support the implementation of a case manager?
-
Review your own current processes relating to ER and IR within the organisation and identify three issues that can be improved upon.
-
A group of students working on a collaborative research project needs a centralized space to store and edit their documents. Which Teams feature should they primarily use?
Study smarter with the SolutionInn App