In Listing 11.10, MyStack is implemented using composition. Define a new stack class that extends ArrayList.Draw the
Question:
In Listing 11.10, MyStack is implemented using composition. Define a new stack class that extends ArrayList.Draw the UML diagram for the classes and then implement MyStack. Write a test program that prompts the user to enter five strings and displays them in reverse order.
Listing
Transcribed Image Text:
1 import java.util.ArrayList; 2 3 public class MyStack { 4 private ArrayList<0bject> list = new ArrayList<>(); 5 public boolean isEmpty() { return list.isEmpty(); 6 public int getSize() { return list.size(); 10 11 12 13 14 public Object peek() { return list.get(getSize() - 1); 15 16 17 18 public Object pop() { Object o = list.get(getSize() - 1); list.remove (getSize() - 1); 19 20 21 22 23 24 25 26 27 28 return o; public void push(0bject o) { list.add(o); @Override public String toString() { return "stack: " + list.toString(); 29 30 31 32 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 20% (5 reviews)
Program that prompts the user to enter five strings and display them in reverse order UML diagram ...View the full answer
Answered By
Sultan Ghulam Dastgir
The following are details of my Areas of Effectiveness English Language Proficiency, Organization Behavior , consumer Behavior and Marketing, Communication, Applied Statistics, Research Methods , Cognitive & Affective Processes, Cognitive & Affective Processes, Data Analysis in Research, Human Resources Management ,Research Project,
Social Psychology, Personality Psychology, Introduction to Applied Areas of Psychology,
Behavioral Neurosdence , Historical and Contemporary Issues in Psychology, Measurement in Psychology, experimental Psychology,
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
In Listing 19.1, GenericStack is implemented using composition. Define a new stack class that extends ArrayList. Draw the UML diagram for the classes and then implement GenericStack. Write a test...
-
In Section 24.5, Stacks and Queues, GenericQueue is implemented using composition. Define a new queue class that extends java.util.LinkedList.
-
Since T is implemented using a list in the getMinimumSpanningTree and getShortestPath methods in Listing 29.2 WeightedGraph.java, testing whether a vertex u is in T by invoking T.contains(u) takes...
-
Divalent carbon species called carbenes care capable of fleeting existence. For example, methylene: CH2, is the simplest carbene. The two unshared electrons in methylene can be either spin-paired in...
-
Construct a 3 ( 3 matrix, not in echelon form, whose columns do not span. Show that the matrix you construct has the desired property. R3
-
Which of the following is not considered a type of E-R diagram? a. DBDL b. ERM c. Crows foot notation d. Access Relationship window
-
Consider the following cash flow diagram. What is the value of \(X\) if the internal rate of return is 15 percent? a. \(\$ 246\) b. \(\$ 255\) c. \(\$ 281\) d. \(\$ 290\) 0 $400 X X 1 2
-
Lebo Hardware reported cost of goods sold as follows. Lebo made two errors: (1) 2010 ending inventory was overstated $3,000, and (2) 2011 ending inventory was understated $6,000.InstructionsCompute...
-
A new university has been built outside a small town in Scotland, which has resulted in a mass influx of workers and their families to the area. As a result of this, the town has been suffering from...
-
A store maintains data on customers, products and purchase records in three tables: CUSTOMER, PRODUCT, PURCHASE. The store manager wants to know which product is on its maximum discount for each...
-
Write the following method that sorts an ArrayList of numbers: public static void sort(ArrayList list) Write a test program that prompts the user to enter 5 numbers, stores them in an array list, and...
-
Write a program that randomly fills in 0s and 1s into an n-by-n matrix, prints the matrix, and finds the rows and columns with the most 1s. Enter the array size n: 4 The random array is 0011 0011...
-
Let f(x) = x 3 , g(x) = sin x, and h(x) = x. a. Evaluate h(g(/2)). b. Find h(f(x)). c. Find f(g(h(x 2 )). d. Find the domain of g f. e. Find the range of f g.
-
A family car went to town (West) around 8 a.m. It traveled 1,150 m and arrived at its destination around 8:36 am. Then, it traveled back home from 3:30 pm to 4:02 pm. Calculate the a) distance, b)...
-
For this assignment, pretend you are a lawyer representing your client Martin Alverez (the defendant). Mr. Alvarez is accused of setting fire to a campus dormitory. Ten students were killed as a...
-
Could you elucidate the distinct human adaptive mechanisms in response to thermal stressors, encompassing heat, cold, and variations in body size and shape, with reference to specific examples?
-
You are driving a souped-up Honda Civic (m = 1350kg) with respectably sticky tires (static friction coefficient of 0.87). What is the fastest speed you can take an unbanked curve (radius = 40.0m)...
-
A is the owner of a life insurance policy on the life of B. A transfers ownership of the policy to B. A dies two years later. What estate tax consequences may A face as a result?
-
Alexander Corporation reports the following components of stockholders' equity on December 31, 2016: Common stock-$25 par value, 50,000 shares authorized, 30,000 shares issued and outstanding . . . ....
-
Calculate Total Contribution Margin for the same items. Total Revenue Total Variable Costs Total Contribution Margin $50.00 a. $116.00 $329.70 b. $275.00 $14,796.00 $7,440.00 c. $40,931.25 d....
-
a. Sunshine Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a Rental class that holds equipment rental information. Now modify the Rental class as...
-
Create a Rock Paper Scissors game in which the user enters a string rock, paper, or scissors. Allow the choice to be valid whether the player enters a choice in uppercase letters, lowercase letters,...
-
a. Yummy Catering provides meals for parties and special events. In previous chapters, you have developed an Event class that holds catering event information. Now modify the Event class as follows:...
-
A proton is going 976 m/s when it is exposed to a 38 T magnetic field (see below) and begins moving in a circle. Determine the direction of the magnetic force, the radius of the motion, and the...
-
Example: A surface charge of 5.0 C/m is located in the x-z plane in the region -2.0 m x 2.0 m and -3.0 m y 3.0 m. Find analytically the electric field at the point (0, 4.0, 0) m. x 3 Ps=5/C/m =2...
-
As shown below, a charged particle is moving through a region that has a uniform 1,400 N/C E-field (the red lines) and a uniform 8.8 T B-field. As a result of these two fields and the resulting...
Study smarter with the SolutionInn App