Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 20, Problem 1AW
Program Plan Intro
Stack:
- A stack is a linear data structure.
- It follows the order FILO (first in last out) LIFO or (last-in-first-out) for performing operations on it.
- The two main operations performed on a stack are,
- Push() – Add item to the stack.
- Pop() – Remove item from the stack.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java:
Class: MiddleStr
Write a method
public static String middle(String str)
that returns a string containing the middle character in str if the length of str is odd, or the two middle characters if the length is even. For example, middle("middle") returns "dd". Write a test program [main()] to test the method.
Use for loop in Java language
Write the method stringSplosion().* * The method takes one parameter, a non-empty String str (such as "Code") and* returns a String in the form "CCoCodCode". Notice that this includes the* first character of the original String, followed by the first two characters,* and so on until the whole String is used.* * Examples: stringSplosion("Code") returns "CCoCodCode" stringSplosion("abc")* returns "aababc" stringSplosion("x") returns "x"* * @param str the input String to process.* @return a new String as described above.
creat a method in (java) that do the following:
This will prompt the user for initial list of letters(a word).Then it will generate all permutations of these letters .Here it has to be mentioned that the permutations can also be of shorter length than the list of letters . For example, if the initial list of letters is "STOP", then "TOP" and "TOPS" are both valid permutations, but "STOPS" isn't
Chapter 20 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 20.3 - Prob. 20.1CPCh. 20.3 - Prob. 20.2CPCh. 20.3 - Prob. 20.4CPCh. 20.3 - Prob. 20.5CPCh. 20.6 - Prob. 20.6CPCh. 20.6 - Prob. 20.7CPCh. 20.6 - Prob. 20.8CPCh. 20.6 - Prob. 20.9CPCh. 20 - Prob. 1MCCh. 20 - Prob. 2MC
Ch. 20 - Prob. 3MCCh. 20 - The concept of seniority, which some employers use...Ch. 20 - Prob. 5MCCh. 20 - Prob. 6MCCh. 20 - Prob. 8TFCh. 20 - Prob. 9TFCh. 20 - Prob. 10TFCh. 20 - Prob. 1FTECh. 20 - Prob. 2FTECh. 20 - Prob. 3FTECh. 20 - Prob. 4FTECh. 20 - Prob. 5FTECh. 20 - Prob. 1AWCh. 20 - Prob. 2AWCh. 20 - Suppose that you have two stacks but no queues....Ch. 20 - Prob. 1SACh. 20 - Prob. 2SACh. 20 - Prob. 3SACh. 20 - Prob. 4SACh. 20 - Prob. 5SACh. 20 - Prob. 6SA
Knowledge Booster
Similar questions
- ممكن الحلarrow_forwardJava programming questionarrow_forwardIn Java Write a method splitStack that takes a stack of integers as a parameter and splits it into negatives and non-negatives. The numbers in the stack should be rearranged so that all the negatives appear on the bottom of the stack and all the non-negatives appear on the top. In other words, if after this method is called you were to pop numbers off the stack, you would first get all the non-negative numbers and then get all the negative numbers. It does not matter what order the numbers appear in as long as all the negatives appear lower in the stack than all the non-negatives. You may use a single queue as temporary storage.arrow_forward
- 1. Write a method called doubleListthat takes an ArrayList of strings as a parameter and replaces every string with two of that same string. For example, if the list stores the values ["how", "are", "you?"] before the method is called, it should store the values ["how", "how", "are", "are", "you?", "you?"] after the method finishes executing.In your program1, you also need to create a class namedProgram1.java, where you are going to construct some arralylists to test the doubleList within the static void main method. In the output, it will print out the original list and the new list after calling the doubleList method. 2.Write a method called filterRange that accepts an ArrayList of integers and two integer values min and max as parameters and removes all elements whose values are in the range min through max (inclusive). For example, if a variable calledlist stores the values [4, 7, 9, 2, 7, 7, 5, 3, 5, 1, 7, 8, 6, 7], the call of filterRange(list, 5, 7);should remove all values…arrow_forwardjava using set or map Write a method called firstUnique() that takes a string as a parameter and finds the first non-repeating character in it by doing only one traversal of it. For example, ‘w’ is the first non-repeating character in the string “hellohowareyou”.arrow_forwardWrite a java program with a method that reverses a string The method must accept one parameter of type String (string to reverse), and returns every second element from the end to the beginning. For example: String: thisisstringResult is: g i t s s harrow_forward
- Write a method that accepts two lists of integer values and checks if theyare identical or not (i.e. contain the same values). if they are not identical, the methodmust display the max value of each list.arrow_forwardNeed help with this in Java Implement a “To Do” list. Tasks have a priority between 1 and 9, and a description (which you can come up with on your own, say, “wash dishes”). The program is going to prompt the user to enter the tasks by running the method add_priority_description, the program adds a new task and prints the current list with priority 1 tasks on the top, and priority 9 tasks at the bottom. The program will continue to ask the user if they want to add another tasks, and repeat the add_priority_description method, or enters Q to run the quit method to quit the program. Sample output (not limited to) 1. Study for the final 1. Take the final 2. Watch Justice League with friends 3. Play ball 9. Wash Dishes 9. Clean room. There is a possibility of two tasks having the same priority. If so, the last task that was entered gets to be printed first. Use HEAP in your solution. (Java)arrow_forwardWrite a java program called ShoppingList.java, which prompts the user to enter a set of grocery items, and stores them in a list using the Java ArrayList Collection class. It then displays the list and asks the user to type in each item when they put it in their shopping cart and remove it from the list. It should work as follows: Welcome to My Shopping List. Please enter an item: Milk Enter another Item Y/N: Y Please enter an item: Bread Enter another Item Y/N: Y Please enter an item: Eggs Enter another Item Y/N: N Here is your Shopping List: Milk Bread Eggs Enter an item to remove from the list: Eggs Eggs has been removed Here is your Shopping List: Milk Bread Enter an item to remove from the list: Milk Milk has been removed Here is your Shopping List: Breadarrow_forward
- Create a Java program. You have a list of Student ID's followed by the course number(separated by aa space) that the student is enrolled in. The listing is in no particular order. For eg. is student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210 then the list may look like this: 1 CS100 2 MATH210 2 CS105 1 CS200 Write a program that reads data in this format from the console. If the ID is -1 then stop inputting data. Use the HashMap class to map from an Integer(Student ID) to an ArrayList of type String that holds each class that the student is enrolled in. The declaration should look like this: HashMap<Integer, ArrayList<String>> students = new HashMap<Integer, ArrayList<String>>(); After all data is input, iterate through the map and output the student ID and all classes stored in the vector for that student. The result should be a list of classes organized by student id.arrow_forwardWrite a program that reads a list of integers from the keyboard and creates thefollowing information.a. Finds and prints the sum and the average of the integersb. Finds and prints the largest and the smallest integerc. Prints a Boolean (true or false) if some of them are less than 20d. Prints a Boolean (true or false) if all of them are between 10 and 90The input data consist of a list of integers with a sentinel. The program mustprompt the user to enter the integers, one by one, and enter the sentinel whenthe end of the list has been reached. The prompt should look like the following: Enter the numbers with <return>(99999 to stop):The output should be formatted as shown below: The number of integers is: xxxThe sum of the integers is: xxxxThe average of the integers is: xxx.xxThe smallest integer is: xxxThe largest integer is: xxxAt least one number was < 20: <true or false>All numbers were ( 10 <= n >= 90): <true or false>arrow_forwardWrite a Java method that merges two sorted lists into a new sorted list. public static int[] merge (int[] 1istl, int[] list2) Write a Java test Program that prompts the user to enter two sorted lists and displays the merged list. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. This number is not part of the list. Enter listl: 5 1 5 16 61 111 JEnter Enter list2: 4 2 4 5 6 -Enter The merged list is 1 2 4 5 5 6 16 61 111arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education