Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 19.2PE
Program Plan Intro

Implement “GenericStack” using inheritance

Program Plan:

  • Include appropriate package “import java.util.Scanner” into program.
  • Define the class named “Exercise19_02”.
    • Define main method.
      • Define the object “obj” for “GenericStack<String>” class.
      • Assign the object for “Scanner” class.
      • Prompt the user and get the strings from user and push the values into stack using “for” loop.
      • Using “for” loop, print array elements in reverse order.
    • Define the class “GenericStack<E>” which extends the “ArrayList<E>” class.
      • Define the Boolean method “isEmpty()” which returns empty value.
      • Define the Integer method “getSize()” which returns size of the stack.
      • Define the method “peek()” which returns top element from the stack.
      • Define the method “pop()” which returns stack elements.
      • Define the method “push()” which inserts the values into stack.
      • Define the method “search()” which searches the index position of the stack.
      • Define the method “toString()” which prints the stack elements.

Blurred answer
Students have asked these similar questions
(Geometry: MyRectangle2D class)  Define the  MyRectangle2D class that contains:  Two double data fields named x and y that specify the center of the rectangle with getter and setter methods. (Assume the rectangle sides are parallel to the x- or y-axis.) The data fields width and height with getter and setter methods. A no-arg constructor that creates a default rectangle with (0, 0) for (x, y) and 1 for both width and height. A Constructor that creates a rectangle with the specified x, y, width, and height. A method getArea() that returns the area of the rectangle. A method getPerimeter() that returns the perimeter of the rectangle. A method contains(double x, double y) that returns true if the specified point (x, y) is inside this rectangle (see Figure 10.24a ). A method contains(MyRectangle2D r) that returns true if the specified rectangle is inside this rectangle (see Figure 10.24b ). A method overlaps(MyRectangle2D r) that returns true if the specified rectangle overlaps with this…
(Sort ArrayList) Write the following method that sorts an ArrayList: public static <E extends Comparable<E>> void sort(ArrayList<E> list) Write a test program that prompts the user to enter 10 integers, invokes this method to sort the numbers, and displays the numbers in increasing order. Sample Run   Enter 10 integers: 3 4 12 7 3 4 5 6 4 7 The sorted numbers are 3 3 4 4 4 5 6 7 7 12 Class Name: Exercise19_09
apartmentList is a pointer to the first node in a linked list of nodes. Use this for Parts a, b, and c. Part a. Create an inner class that will hold the following information: the apartment number of the apartment (an int), the number of bedrooms in the apartment (also an int), the current rent of the apartment (a double). Don't forget to include a field for the link! Just create the class itself and the instance variables; you don't need to put any methods into the class.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning