
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question

Transcribed Image Text:Implement RemoveLastCommand's execute() method to remove source_list's last element.
Step 4: Implement GroceryList's execute_undo() method
Implement GroceryList's execute_undo() method to do the following:
Pop an UndoCommand off the undo stack
• Execute the popped undo command
File main.py has code that reads in a list of commands, one per line, that allow for basic testing of basic operations. So after implementing
execute_undo(), run your program with the following input:
add bananas
add grapes
add strawberries
print
undo
print
undo
print
quit
Verify that the corresponding output is:
0. bananas
1. grapes
2. strawberries
0. bananas
1. grapes
0. bananas
The program's output does not affect grading, so additional test cases can be added, if desired.
Submitting code written so far to obtain partial credit is recommended before proceeding to the next step.
Step 5: Implement the SwapCommand class and GroceryList's swap_with_undo() method
![Emport sys
from GroceryList import GroceryList
def main():
grocery_list
if
quit
False
while not quit:
command
=
input()
# Process user input
if command
"print":
elif 0 ==
elif 0
elif 0
=
grocery_list.print_list(sys.stdout)
command.find("add "):
grocery_list.add_with_undo (command [4:])
command.find("removeat "):
else:
=
grocery_list.remove_at_with_undo(int(command [9:]))
parse_indices (command [5:])
index2)
name
else:
GroceryList()
index1, index2
else:
grocery_list.swap_with_undo(index1,
==
if index2 < 0:
print(""swap" command requires two indices, separated by a space. ex: swap 25')
grocery_list. swap_with_undo(index1, index2)
elif command
if 0
else:
command.find("swap "):
1
==
elif command
quit
grocery_list.get_undo_stack_size():
print("Cannot execute undo because undo stack is empty")
=
grocery_list.execute_undo()
"quit":
def parse_indices(str):
"undo":
True
print("unknown command: ", command)
indices = [int(n) for n in str.split()]
if len(indices) != 2:
return -1, -1
return indices
_main__':](https://content.bartleby.com/qna-images/question/4ae6a9f2-4432-4b02-8538-0db0162b52d1/f81acd96-40b2-4b2e-8759-c3ed1eb8cad9/nt9ft2y_thumbnail.png)
Transcribed Image Text:Emport sys
from GroceryList import GroceryList
def main():
grocery_list
if
quit
False
while not quit:
command
=
input()
# Process user input
if command
"print":
elif 0 ==
elif 0
elif 0
=
grocery_list.print_list(sys.stdout)
command.find("add "):
grocery_list.add_with_undo (command [4:])
command.find("removeat "):
else:
=
grocery_list.remove_at_with_undo(int(command [9:]))
parse_indices (command [5:])
index2)
name
else:
GroceryList()
index1, index2
else:
grocery_list.swap_with_undo(index1,
==
if index2 < 0:
print(""swap" command requires two indices, separated by a space. ex: swap 25')
grocery_list. swap_with_undo(index1, index2)
elif command
if 0
else:
command.find("swap "):
1
==
elif command
quit
grocery_list.get_undo_stack_size():
print("Cannot execute undo because undo stack is empty")
=
grocery_list.execute_undo()
"quit":
def parse_indices(str):
"undo":
True
print("unknown command: ", command)
indices = [int(n) for n in str.split()]
if len(indices) != 2:
return -1, -1
return indices
_main__':
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

Knowledge Booster
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
- I need some help making this code more simple. 2) AlgorithmtokenList = "{}()[]"initialize stack to emptyGet file name from user: fileNameOpen the file (fileName)read line from fileName into strLinewhile not EOF (end of file)find tokenList items in strLine for each token in strLineif token = "[" thenpush "]" into stackelse if token = "(" thenpush ")" into stackelse if token = "{" thenpush "}" into stackelse if token = "]" OR token = ")" OR token = "}" thenpop stack into poppedTokenif poppedToken not equal tokenprint "Incorrect Grouping Pairs"exitend ifend ifnext tokenend whileif stack is emptyprint "Correct Grouping Pairs"elseprint "Incorrect Grouping Pairs"end ifarrow_forwardMake use of a random number generator to generate a list of 500 three-digit numbers. Create a sequential list FILE of the 500 numbers. Artificially implement storage blocks on the sequential list with every block containing a maximum of 10 numbers only. Open an index INDX over the sequential list FILE which records the highest key in each storage block and the address of the storage block. Implement Indexed Sequential search to look for keys K in FILE. Compare the number of comparisons made by the search with that of the sequential search for the same set of keys.Extend the implementation to include an index over the index INDX.arrow_forwardThis is the wrong output. Please look at the expected output that is attached. And print out the expected output with the correct code.arrow_forward
- In Java Integer in is read from input. Write a while loop that iterates until in is less than or equal to 0. In each iteration: Update in with the quotient of in and 7. Output the updated in, followed by a newline. Click here for exampleEx: If the input is 2401, then the output is: 343 49 7 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.Scanner; public class QuotientCalculator { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); intin; in=scnr.nextInt(); /your code here/ } }arrow_forwardWrite a program that obtains the executiontime of external sorts for integers of size 6,000,000, 12,000,000, 18,000,000,24,000,000, 30,000,000, and 36,000,000. Your program should print a tablelike this:arrow_forwardCan you help me write the code for this one please? Thank youarrow_forward
- Use stacks to implement a postfix-to-infix translator. Until the user closes the programme, it should continually read a postfix expression and output the identical infix expression. If the postfix expression entered is incorrect, throw an exception.arrow_forwardReview Loops Write a java program to ask three people three questions about name, number of courses, and number of credit hours. Also, print result in columns as below. Note: the input.nextInt() method reads only the integer value from input buffer.The "\n" is still staying in the input buffer. If you continue reading with input.nextLine(),you will receive the "\n" and CPU will not wait for any input. To fix this problem, you addthe statement input.nextLine() to flush out the "\n" from the input buffer.arrow_forwardA controlled transaction solution for Joe's Pizza, your friendly neighborhood pizza shop.Joe only make $200 worth of pizza everyday. Modify your program so that if the running total will exceed $200, print a warning and DO NOT add this value to running total. Instead, go to the beginning of loop statement block and wait for next transaction. can you please write it in import java.util.Scanner; and can you make it so i can copy and past it. thank you in advance the code from before /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package personal;import java.util.Scanner;/** * * @author Mabda */public class Personal { /** * @param args the command line arguments */ public static void main(String[] args) { int num, sum = 0; char choice; Scanner key = new Scanner(System.in); while (true) {…arrow_forward
- This code has a delay in the loop, during which time the user inputs will be ignored. So, please modify it and implement a solution that would trigger the needed function when there is an input. // Pin numbers written on the board itself do not correspond to Aurdino pinnumbers.Constants are defined to make using this board easierconst uint8_t BTN_PIN = 2;const uint8_t LED_PIN = 13;//assigning button;s previous state and LedSate to LOWuint8_t buttonPrevState = LOW;uint8_t ledState = LOW;//defining a new functionvoid setup(){// Assigning the types of input parameterspinMode(BTN_PIN, INPUT_PULLUP);//Assigning the types of output parameterspinMode(LED_PIN, OUTPUT);//begin of process detailsSerial.begin(9600);}void loop(){//assigning button state to be read modeuint8_t buttonState = digitalRead(BTN_PIN); //To print the following in output windowSerial.print(buttonState);Serial.print(buttonPrevState);Serial.print(ledState);Serial.println(""); //check if the button state presently is same…arrow_forward/*TASK 5. Implement part 1 of the report. You need to read data from input.txt file, store it into array of items (called items) and write it in a formatted form to the output file. Code, debug and present it in the best possible format. Hint: It might be helpful to format the String coming from toString( ) method using String.format( ) method, which works similar to System.out.prinf. Hint2: You might have to close and delete existing output .doc or .txt file from its folder * public class YourUserName_hw7 { static Item [ ] items = new Item [200];//an array of Items static EdibleItem [ ] edibleItems;//an array of Edible Items static int countEdibleitems = 0;//count edible items static String pageHeader; //save the header //main( ) method runs the program public static void main(String[ ] args) throws FileNotFoundException { double sum = 0, average = 0; //Optional - create a new input file //CreateInput.createInputFile( );…arrow_forwardIt is a python program. Make sure it works and run in IDLE 3.10. Please show the code screenshot and output screenshot.arrow_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