Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java data structure - the previous hw grocerybag is in the pics This homework includes two questions, Q1 is mandatory and Q2 is a bonus.

java data structure - the previous hw grocerybag is in the pics image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
This homework includes two questions, Q1 is mandatory and Q2 is a bonus. Q1. In the previous homework, you wrote a GroceryBag application. You will use your code to add more features to your application. Your application should now support new operation: Undo. As the name of the operation suggest, Undo will undo what ever operation the user performed before it. Use an array stack to implement the undo operation. Note that Undo can only be applied to: 1) Add item to the bag 2) Remove an item from the bag Also, you will work with only one bag, so you need an undo stack for bag 1 only. Undo operation has a limit of only 5 operations. If your stack fills up, remove the oldest operation (shift the elements to the left to make room for the new value). Hint: since you need to undo two operations (add item, remove item) then your stack should store both the element and the operation (add or remove) to be able to undo the previous operation correctly. For example: If the user performed the following Add item: milk egg Add item: muffins Add item: Strawberry the content of the bag will be: milk egg muffins Strawberry Undo the content of the bag will be: milk egg muffins Undo the content of the bag will be: milk egg remove: milk the content of the bag will be: ege Undo the content of the bag will be: egg milk The menu for your GroceryBag application should change to: 1) Add item to the bag 2) Remove an item from the bag 3) Display the content of the bag 4) Undo 5) Exit Note: If add item, remove item, and print methods from last homework have errors, fix them first. The other methods from the previous homework are not needed so you don't need to worry about them. Write a program to test undo and redo. doubly linked has same feature except in doubly w can traverse in both the direction but for this problem this is not needed Part 2.3.4 import java.util.Scanner: Elastem String data, Item next ItemString data) this.data-data; 2 class Grocery Bao Item head staticities GroceryBago { head=null si > public boolean addString newem) Item tem new iteminewitem: siz heade nuit 1 head=item; return true, ) Item temanhead while(tomp.extenull) 1 temamp.net 1 itempat return false temp.next=item; return true; remove method public String remove(String antem empre ultem: tempuhead: Search for required tem in grocery Bag whiletomaten item data qualsaniemi ifre null) if the first femismatched headhead.net return anter > else pre nextstemp.next; return antem 2 prestem tempstemp.net 1 return null clear method public void card teadnult size Tad Garcia Method public containing fount med tem re DOS mi is pcccani Polic as Saptap emmat Symo proposal rocery more for doing ceyrando recht Ocena w Grocery medad that be recerca Grocery manerad carini rence w he Diary Bow Broca the continutul reddet 1 gublic class Cher public void mao Scanners Scarvest Grocery bagten Grecia Grocery Bay Date Orecer Secto Grocery w System.out.prinese Oystem System Ademia ve anatambah of a Systems the to System.Date many the content Syntheon RICE Seminte de watch Synowie we freemouth CORO be og Strings 1 bag. brk Badea w bago str=sc.next(): if(str.equals("S"> . M break; 1 bag1.add(str); 2 else String str=" while(true) stresc.next; if(str.equals("")) break; 1 bag2.add(str): 2 > break; case 2: String stresc.next(); bag1.remove(str); break; case 3: bagi.clear(); break; case 4: strasc.next: bag1.contains(str); break case 5: strasc.next(): int count-bagi.count(str); break; case 6: count=bag1.getSize(); break; case 7: bag1.display: break; case 8: GroceryBag union-bagt.union(bag): break; case 9: GroceryBag intersection-bag1.intersection(bag2); break; case 10: GroceryBag diff-bag 1.difference(bag) break; case 11: System.exit(0); 3 01. In the previous homework, you wrote a GroceryBag application. You will use your code to add more features to your application. Your application should now support new operation: Undo. As the name of the operation suggest, Undo will undo what ever operation the user performed before it Use an array stack to implement the undo operation. Note that Undo can only be applied to: 1) Add item to the bag 2) Remove an item from the bag Also, you will work with only one bag, so you need an undo stack for bag 1 only. Undo operation has a limit of only 5 operations. If your stack fills up, remove the oldest operation (shift the elements to the left to make room for the new value). Hint: since you need to undo two operations (add item, remove item) then your stock should store both the element and the operation (add or remove) to be able to undo the previous operation correctly For example: if the user performed the following Add item: milk ege Add item: muffins Add item: Strawberry the content of the bag will be milk egg muffins Strawberry Undo the content of the bag will be milk egg muffins Undo the content of the bag will be milk ese remove: milk the content of the bag will be es Undo the content of the bag will be egg milk The menu for your Grocerypag application should change to: 1) Add item to the bag 2) Remove an item from the bag 3) Display the content of the bag 4) Undo 5) Exit Note: If add item, remove item, and print methods from last homework have errors, fix them first. The other methods from the previous homework are not needed so you don't need to worry about them Write a program to test undo and redo. This homework includes two questions, Q1 is mandatory and Q2 is a bonus. Q1. In the previous homework, you wrote a GroceryBag application. You will use your code to add more features to your application. Your application should now support new operation: Undo. As the name of the operation suggest, Undo will undo what ever operation the user performed before it. Use an array stack to implement the undo operation. Note that Undo can only be applied to: 1) Add item to the bag 2) Remove an item from the bag Also, you will work with only one bag, so you need an undo stack for bag 1 only. Undo operation has a limit of only 5 operations. If your stack fills up, remove the oldest operation (shift the elements to the left to make room for the new value). Hint: since you need to undo two operations (add item, remove item) then your stack should store both the element and the operation (add or remove) to be able to undo the previous operation correctly. For example: If the user performed the following Add item: milk egg Add item: muffins Add item: Strawberry the content of the bag will be: milk egg muffins Strawberry Undo the content of the bag will be: milk egg muffins Undo the content of the bag will be: milk egg remove: milk the content of the bag will be: ege Undo the content of the bag will be: egg milk The menu for your GroceryBag application should change to: 1) Add item to the bag 2) Remove an item from the bag 3) Display the content of the bag 4) Undo 5) Exit Note: If add item, remove item, and print methods from last homework have errors, fix them first. The other methods from the previous homework are not needed so you don't need to worry about them. Write a program to test undo and redo. doubly linked has same feature except in doubly w can traverse in both the direction but for this problem this is not needed Part 2.3.4 import java.util.Scanner: Elastem String data, Item next ItemString data) this.data-data; 2 class Grocery Bao Item head staticities GroceryBago { head=null si > public boolean addString newem) Item tem new iteminewitem: siz heade nuit 1 head=item; return true, ) Item temanhead while(tomp.extenull) 1 temamp.net 1 itempat return false temp.next=item; return true; remove method public String remove(String antem empre ultem: tempuhead: Search for required tem in grocery Bag whiletomaten item data qualsaniemi ifre null) if the first femismatched headhead.net return anter > else pre nextstemp.next; return antem 2 prestem tempstemp.net 1 return null clear method public void card teadnult size Tad Garcia Method public containing fount med tem re DOS mi is pcccani Polic as Saptap emmat Symo proposal rocery more for doing ceyrando recht Ocena w Grocery medad that be recerca Grocery manerad carini rence w he Diary Bow Broca the continutul reddet 1 gublic class Cher public void mao Scanners Scarvest Grocery bagten Grecia Grocery Bay Date Orecer Secto Grocery w System.out.prinese Oystem System Ademia ve anatambah of a Systems the to System.Date many the content Syntheon RICE Seminte de watch Synowie we freemouth CORO be og Strings 1 bag. brk Badea w bago str=sc.next(): if(str.equals("S"> . M break; 1 bag1.add(str); 2 else String str=" while(true) stresc.next; if(str.equals("")) break; 1 bag2.add(str): 2 > break; case 2: String stresc.next(); bag1.remove(str); break; case 3: bagi.clear(); break; case 4: strasc.next: bag1.contains(str); break case 5: strasc.next(): int count-bagi.count(str); break; case 6: count=bag1.getSize(); break; case 7: bag1.display: break; case 8: GroceryBag union-bagt.union(bag): break; case 9: GroceryBag intersection-bag1.intersection(bag2); break; case 10: GroceryBag diff-bag 1.difference(bag) break; case 11: System.exit(0); 3 01. In the previous homework, you wrote a GroceryBag application. You will use your code to add more features to your application. Your application should now support new operation: Undo. As the name of the operation suggest, Undo will undo what ever operation the user performed before it Use an array stack to implement the undo operation. Note that Undo can only be applied to: 1) Add item to the bag 2) Remove an item from the bag Also, you will work with only one bag, so you need an undo stack for bag 1 only. Undo operation has a limit of only 5 operations. If your stack fills up, remove the oldest operation (shift the elements to the left to make room for the new value). Hint: since you need to undo two operations (add item, remove item) then your stock should store both the element and the operation (add or remove) to be able to undo the previous operation correctly For example: if the user performed the following Add item: milk ege Add item: muffins Add item: Strawberry the content of the bag will be milk egg muffins Strawberry Undo the content of the bag will be milk egg muffins Undo the content of the bag will be milk ese remove: milk the content of the bag will be es Undo the content of the bag will be egg milk The menu for your Grocerypag application should change to: 1) Add item to the bag 2) Remove an item from the bag 3) Display the content of the bag 4) Undo 5) Exit Note: If add item, remove item, and print methods from last homework have errors, fix them first. The other methods from the previous homework are not needed so you don't need to worry about them Write a program to test undo and redo

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago