In Listing 19.1, GenericStack is implemented using composition. Define a new stack class that extends ArrayList. Draw
Question:
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 program that prompts the user to enter five strings and displays them in reverse order.
Listing
Transcribed Image Text:
1 public class GenericStack
1 public class GenericStack { private java.util.ArrayList list = new java.util.ArrayList<>(); 3 public int getSize() { return list.size(); 4. 5 6. public E peek() { return list.get (getSize() - 1); 10 11 public void push(E o) { list.add(o); 12 13 14 15 16 17 18 19 20 public E pop() { E o = list.get(getSize() - 1); list.remove(getSize() - 1); return o; 21 22 public boolean isEmpty() { return list.isEmpty(); 23 24 25 @0verride public String toString() { return "stack: 26 27 + list.toString(); 28 29 30 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 62% (8 reviews)
Program Plan Create a class called Stack The class Stack that extends the Class ArrayLis...View the full answer
Answered By
Simon kingori
I am a tier-one market researcher and content developer who has been in this field for the last six years. I’ve run the freelancing gamut; from market research, data mining and SEO/SMM to copywriting, Content Development, you name it, I’ve done it. I’m extremely motivated, organized and disciplined – you have to be to work from home. My experience in Freelancing is invaluable- but what makes me a cut above the rest is my passion to deliver quality results to all my clients- it’s important to note, I've never had a dissatisfied client. Backed by a Masters degree in Computer Science from MOI university, I have the required skill set and burning passion and desire to deliver the best results for my clients. This is the reason why I am a cut above the rest. Having taken a Bsc. in computer science and statistics, I deal with all round fields in the IT category. It is a field i enjoy working in as it is dynamic and new things present themselves every day for research and exploration.
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 Programming Exercise 9.7, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to...
-
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...
-
In Section 24.5, Stacks and Queues, GenericQueue is implemented using composition. Define a new queue class that extends java.util.LinkedList.
-
Runnals National Bank has experienced the following trends over the past five years (all figures in millions of dollars): Input Area: 1 2 3 4 5 Net Income (after tax) 2.65 2.75 3.25 3.65 4.00 Total...
-
1. For any lattice X, the strong set order
-
The nation of Temeria is able to produce ships and raise horses in combinations represented by the data in the following table. Each number represents hundreds of units. Explain why the data shows...
-
Copy your worksheet from Question 6 into another worksheet. Change the increase from 10% to 18%. Protect the worksheet, so that changes cannot be made. Question 6 Open a new spreadsheet. Type...
-
Anglers Dream Company supplies flies and fishing gear to sporting goods stores and outfitters throughout the western United States. The accounts receivable clerk for Anglers Dream prepared the...
-
Pops Popcorn has three project choices for the coming year, but only $9,000 in its budget for new projects. Project 1 is a new corn seed separator that identifies grannies (seeds that do not pop when...
-
San Diego Harbor Tours has poor internal control over cash. Ben Johnson, the owner, suspects the cashier of stealing. Here are some details of company cash at September 30: a. The Cash account in the...
-
Write the following method that returns a new ArrayList. The new list contains the non-duplicate elements from the original list. public static ArrayList removeDuplicates(ArrayList list)
-
Revise the GenericStack class in Listing 19.1 to implement it using an array rather than an ArrayList. You should check the array size before adding a new element to the stack. If the array is full,...
-
Historically, the probability that a passenger will miss a flight is 0.0995. Source: Passenger-Based Predictive Modeling of Airline No-show Rates by Richard D. Lawrence, Se June Hong, and Jacques...
-
For each of the following, determine whether the item is a private good, impure public good or a pure public good. Explain your response based on the items characteristics. [2] Wilderness areas...
-
An accounting firm (ML) is having Nazri, Najib and Gan as its partners. The business of ML has been badly impacted during the Covid-19 pandemic. Advise all the partners in respect of the following...
-
If you could control any element of supply or demand in a health economy - (workers, services, ....open/ restrict/ etc) what would you do and why? Explaijn
-
A motel in New Orleans charges $90 per day for double occupancy and $80 per day for single occupancy during off-season. If 80 rooms are occupied for a total of $6930, how many rooms of each kind are...
-
Consider a monopolist with the (inverse) demand function: Pb = 372 - 8 Qb. Given an increasing marginal cost: mc = 69 + 7 Q, how much profit does the monopolist earn ? (Assume fixed costs = 68 .)
-
Which of the proposed supply-side tax cuts appeals to you most? Draw up a list of arguments for and against enacting such a cut right now.
-
Cable Corporation is 60% owned by Anna and 40% owned by Jim, who are unrelated. It has noncash assets, which it sells to an unrelated purchaser for $100,000 in cash and $900,000 in installment...
-
Argue why any solution to the previous problem must run in (n) time.
-
Given an array A of n positive integers, each represented with k = logn+1 bits, describe an O(n)-time method for finding a k-bit integer not in A.
-
An evil king has n bottles of wine, and a spy has just poisoned one of them. Unfortunately, they do not know which one it is. The poison is very deadly; just one drop diluted even a billion to one...
-
On January 1, 2020, Mr. Wild formed a corporation to provide services to clients. Information about the first year of operation follows: Jan. 1 Investors provided $1,500,000 in cash in exchange for...
-
What is the purpose of the statement of cash flows? What information does it provide? (b) Prepare the operating activities section of the statement of cash flows for the year ended December 31, 2018,...
-
The cash account for Brentwood Bike Co. at May 1 indicated a balance of $14,640. During May, the total cash deposited was $73,260 and checks written totaled $68,020. The bank statement indicated a...
Study smarter with the SolutionInn App