The main goals for this lab are:
You will need to have a TA check off on all your exercises. If you do not complete the lab during the lab session, you must have a TA check off all your exercises during office hours.
During today’s class we introduced checkstyle. Checkstyle is an open-sourced tool that allows one to easily check whether their code complies with customizable rules.
Your task is to modify LookupZip.java from lecture08 so that the checkstyle passes.
Getting Started:
wget https://raw.githubusercontent.com/BMC-CS-151/class-examples-f23/main/cs151_checks.xmljava -jar checkstyle-8.16-all.jar –c cs151_checks.xml LookupZip.java
to see the checkstyle errors.LookupZip.java until the above command runs without any errors.Now we are going to implement 2 stacks using 1 array.
Imlement a DoubleStack class using a single underlying array
that stores two different stacks (stack 1 and stack 2).
One of the stacks grows upwards
from index 0 upward, and the other stacks grows from the end of the array down. So these two stacks
grow towards each other. Unlike ExpandableArray you can have empty spaces in your data structure.
The top indexes are denoted by top1 and top2 for stack 1 and
stack 2, respectively. Thus, the DoubleStack class should have three instance variables:
Make sure theArray locations 0 to top1 contain elements in stack 1 and theArray locations
theArray.length-1 downto top2 stores the elements in stack 2. You can assume a max stack size of 100 for each stack.
Implement the following methods.
If the runtime of any of the methods besides for printStack is not
O(1), you are writing unnecessary loops.
Before implementing the tests, make sure to create a test fille called TestDoubleStack.java
that uses JUnit tests.
push e onto stack stackId (1 or 2). In other words, it
will push onto stack 1 if stackId==1 and onto stack 2 if stackId==2. Throw an
IllegalStateException if stack is full. Throw an IllegalArgumentException if the stackId is not 1 or 2.
pop from stackId, return null if empty. Throw an IllegalArgumentException if the stackId is not 1 or 2.
top element from stackId, return null if empty. Throw an IllegalArgumentException if the stackId is not 1 or 2.
return size of stack stackId. Throw an IllegalArgumentException if the stackId is not 1 or 2.
Throw an IllegalArgumentException if the stackId is not 1 or 2.
Throw an IllegalArgumentException if the stackId is not 1 or 2.
In todays lab we covered checkstyle, stacks, and unit testing.
Before leaving, make sure your TA/instructor have signed you out of the lab. If you finish the lab early, you are free to go. If you do not finish the lab in time, you will need to go to office hours so that a TA can check your work.