Question

In: Computer Science

package klutseProgStacks; /** Programmed by Stephen Brower Inspired by Michael Main Date Written 10/3/2014 - made...

package klutseProgStacks;

/**
Programmed by Stephen Brower
Inspired by Michael Main
Date Written 10/3/2014 - made tester generic
Date Modified 10/12/2014 - changed to use stacks
* 3/6/2019 - added extra pop

Run this program using the following:
RunTestStackWithCar.java
RunTestStackWithInteger.java
RunTestStackWithString.java
* @param
*/
public class TestStackGenericV2 {
public void test(E [] testDataAdd, E additionalItemToAdd)
{
// creates a Stack
Stack myGenericStack = new Stack( );

// holds an item removed
E itemRemoved = null;

int checkItem = 0;

// show initial stack size
displayStackSize("Display Stack Size on startup",myGenericStack, checkItem);

// add some stuff to the stack
System.out.println("\n===========\n< for (E item : testDataAdd)
{
System.out.print("Pushing: " + item);
myGenericStack.push(item);
checkItem++;
System.out.print(" \tpushed...now size is " + myGenericStack.size());
if (checkItem == myGenericStack.size())
System.out.println(" -good");
else
System.out.println(" no, expected " + checkItem + "\t\t<=== issue");
}
System.out.println("Stopped Pushing>>\n===========");

// show stack size after adds
displayStackSize("\nDisplay stack size after adds",myGenericStack, checkItem);

// set index for checking to the end of the testDataAdd array
checkItem = testDataAdd.length;

System.out.print("\npop?");

// remove 1 item
itemRemoved = myGenericStack.pop();
checkItem--;
// display 1 item
System.out.print("...popped: <" + itemRemoved
+ "> exp:{" + testDataAdd[checkItem]
+ "} \tsize: " + myGenericStack.size());
if (itemRemoved.equals(testDataAdd[checkItem]) && checkItem == myGenericStack.size())
System.out.println(" -good");
else
System.out.println(" exp:"+checkItem+"\t\t<=== issue");


// show stack size after 1 pop
displayStackSize("Display stack size after 1 pop",myGenericStack, checkItem);

// pop all
System.out.println("\n===========\n< while (myGenericStack.size() > 0)
{
System.out.print("pop?");

// remove 1 item
itemRemoved = myGenericStack.pop();
checkItem--;
// display 1 item
System.out.print("...popped: <" + itemRemoved
+ "> exp:{" + testDataAdd[checkItem]
+ "} \tsize: " + myGenericStack.size());
if (itemRemoved.equals(testDataAdd[checkItem]) && checkItem == myGenericStack.size())
System.out.println(" -good");
else
System.out.println(" exp:"+checkItem+"\t\t<=== issue");
}
System.out.println("Stopped Popping>>\n===========");

// show stack size after poping all
displayStackSize("Display stack size after pop all",myGenericStack, checkItem);

System.out.print("\nattempt to remove item from empty stack:\npop?");

itemRemoved = myGenericStack.pop();
// display 1 item
System.out.println("...popped: <" + itemRemoved
+ "> expected EmptyStack Exception"
+ " \tsize: " + myGenericStack.size()+"\t\t<==issue");
  
// show stack size after 1 additional pop
displayStackSize("Display stack size after 1 pop",myGenericStack, checkItem);
  
// push 1 item
myGenericStack.push(additionalItemToAdd);
  
// show stack size after 1 additional push
displayStackSize("Display stack size after 1 additional push",myGenericStack, 1);
  
System.out.print("\npop the additional item");

// remove 1 item
itemRemoved = myGenericStack.pop();
// display 1 item
System.out.print("...popped: <" + itemRemoved
+ "> exp:{" + additionalItemToAdd
+ "} \tsize: " + myGenericStack.size());
if (itemRemoved.equals(additionalItemToAdd) && myGenericStack.size() == 0)
System.out.println(" -good");
else
System.out.println(" exp:"+checkItem+"\t\t<=== issue");
  
// show stack size after 1 additional pop
displayStackSize("Display stack size after 1 pop",myGenericStack, checkItem);
}

/**
the displayBag method displays the linked bag
@param heading a String to display before the bag
@param aBag the LinkedBag to display
*/
private void displayStackSize(String heading, Stack aStack, int expected)
{
System.out.println("\n" + heading);
System.out.print("Size: " + aStack.size());
if (expected == aStack.size())
System.out.println(" -good");
else
System.out.println(" exp: " + expected+"\t\t<=== issue");


}
}

its giving an error on line 34

Solutions

Expert Solution

//It will run fain if you add  package klutseProgStacks and filename according to function

package klutseProgStacks;

/**
Programmed by Stephen Brower
Inspired by Michael Main
Date Written 10/3/2014 - made tester generic
Date Modified 10/12/2014 - changed to use stacks
* 3/6/2019 - added extra pop

Run this program using the following:
RunTestStackWithCar.java
RunTestStackWithInteger.java
RunTestStackWithString.java
* @param
*/
public class TestStackGenericV2 {
public void test(E [] testDataAdd, E additionalItemToAdd)
{
// creates a Stack
Stack myGenericStack = new Stack( );

// holds an item removed
E itemRemoved = null;

int checkItem = 0;

// show initial stack size
displayStackSize("Display Stack Size on startup",myGenericStack, checkItem);

// add some stuff to the stack
System.out.println("\n===========\n");
for (E item : testDataAdd)
{
System.out.print("Pushing: " + item);
myGenericStack.push(item);
checkItem++;
System.out.print(" \tpushed...now size is " + myGenericStack.size());
if (checkItem == myGenericStack.size())
System.out.println(" -good");
else
System.out.println(" no, expected " + checkItem + "\t\t<=== issue");
}
System.out.println("Stopped Pushing>>\n===========");

// show stack size after adds
displayStackSize("\nDisplay stack size after adds",myGenericStack, checkItem);

// set index for checking to the end of the testDataAdd array
checkItem = testDataAdd.length;

System.out.print("\npop?");

// remove 1 item
itemRemoved = myGenericStack.pop();
checkItem--;
// display 1 item
System.out.print("...popped: <" + itemRemoved
+ "> exp:{" + testDataAdd[checkItem]
+ "} \tsize: " + myGenericStack.size());
if (itemRemoved.equals(testDataAdd[checkItem]) && checkItem == myGenericStack.size())
System.out.println(" -good");
else
System.out.println(" exp:"+checkItem+"\t\t<=== issue");


// show stack size after 1 pop
displayStackSize("Display stack size after 1 pop",myGenericStack, checkItem);

// pop all
System.out.println("\n===========\n");
while (myGenericStack.size() > 0)
{
System.out.print("pop?");

// remove 1 item
itemRemoved = myGenericStack.pop();
checkItem--;
// display 1 item
System.out.print("...popped: <" + itemRemoved
+ "> exp:{" + testDataAdd[checkItem]
+ "} \tsize: " + myGenericStack.size());
if (itemRemoved.equals(testDataAdd[checkItem]) && checkItem == myGenericStack.size())
System.out.println(" -good");
else
System.out.println(" exp:"+checkItem+"\t\t<=== issue");
}
System.out.println("Stopped Popping>>\n===========");

// show stack size after poping all
displayStackSize("Display stack size after pop all",myGenericStack, checkItem);

System.out.print("\nattempt to remove item from empty stack:\npop?");

itemRemoved = myGenericStack.pop();
// display 1 item
System.out.println("...popped: <" + itemRemoved
+ "> expected EmptyStack Exception"
+ " \tsize: " + myGenericStack.size()+"\t\t<==issue");
  
// show stack size after 1 additional pop
displayStackSize("Display stack size after 1 pop",myGenericStack, checkItem);
  
// push 1 item
myGenericStack.push(additionalItemToAdd);
  
// show stack size after 1 additional push
displayStackSize("Display stack size after 1 additional push",myGenericStack, 1);
  
System.out.print("\npop the additional item");

// remove 1 item
itemRemoved = myGenericStack.pop();
// display 1 item
System.out.print("...popped: <" + itemRemoved
+ "> exp:{" + additionalItemToAdd
+ "} \tsize: " + myGenericStack.size());
if (itemRemoved.equals(additionalItemToAdd) && myGenericStack.size() == 0)
System.out.println(" -good");
else
System.out.println(" exp:"+checkItem+"\t\t<=== issue");
  
// show stack size after 1 additional pop
displayStackSize("Display stack size after 1 pop",myGenericStack, checkItem);
}

/**
the displayBag method displays the linked bag
@param heading a String to display before the bag
@param aBag the LinkedBag to display
*/
private void displayStackSize(String heading, Stack aStack, int expected)
{
System.out.println("\n" + heading);
System.out.print("Size: " + aStack.size());
if (expected == aStack.size())
System.out.println(" -good");
else
System.out.println(" exp: " + expected+"\t\t<=== issue");


}
}


Related Solutions

Mr.Ahmed made a written contract with Mr.Hamood, on March 2 nd 2020, promising to sell 10...
Mr.Ahmed made a written contract with Mr.Hamood, on March 2 nd 2020, promising to sell 10 computers, for a total price of 2000 (Omani Rials), by 1 st April, 2020. It is also agreed that if computers are not supplied till 1 st April, 2020, Mr.Ahmed should pay damages of 500(Omani Rials) to Mr.Hamood. On 20 th March lockdown declared by government, all businesses are closed till 1 st May 2020, including selling and buying of computers. Due to which...
Mr.Ahmed made a written contract with Mr.Hamood, on March 2nd 2020, promising to sell 10 computers,...
Mr.Ahmed made a written contract with Mr.Hamood, on March 2nd 2020, promising to sell 10 computers, for a total price of 2000 (Omani Rials), by 1st April, 2020. It is also agreed that if computers are not supplied till 1st April, 2020, Mr.Ahmed should pay damages of 500(Omani Rials) to Mr.Hamood. On 20th March lockdown declared by government, all businesses are closed till 1st May 2020, including selling and buying of computers. Due to which Mr.Ahmed could not able to...
a) What is the pH of a buffer made by adding 2.91*10^(-2) NaHCO3 and 4.30*10^(-3) M...
a) What is the pH of a buffer made by adding 2.91*10^(-2) NaHCO3 and 4.30*10^(-3) M Na2CO3 t owater in a closed system? b) What is the pH of the buffer after addition of 10^(-3) M H2SO4? The system is still closed. c) If the bfufer in part a is opened to an atmosphere with Pco2-10^(-3.46) atm, what is the resulting pH? Does Ctco3 increase or decrease, by how much?
A mixture is made by combining 11.5 mL of 8.5×10−3 M KSCN, 6.3 mL of 3.7×10−2...
A mixture is made by combining 11.5 mL of 8.5×10−3 M KSCN, 6.3 mL of 3.7×10−2 M Fe(NO3)3, and 10.4 mL of 0.397 M HNO3. Calculate the concentraion of Fe3+ in the solution.
A mixture is made by combining 19.9 mL of 1.2×10−3 M KSCN, 8.5 mL of 8.1×10−2...
A mixture is made by combining 19.9 mL of 1.2×10−3 M KSCN, 8.5 mL of 8.1×10−2 M Fe(NO3)3, and 11 mL of 0.198 M HNO3. Calculate the concentration of Fe3+ in the solution.
A mixture is made by combining 14 mL of 1.9×10−3 M KSCN, 7.8 mL of 9.1×10−2...
A mixture is made by combining 14 mL of 1.9×10−3 M KSCN, 7.8 mL of 9.1×10−2 M Fe(NO3)3, and 11.7 mL of 0.475 M HNO3. Calculate the concentraion of Fe3+ in the solution.
Write code in your “main” function that performs the following: a) For each n є {10^3,...
Write code in your “main” function that performs the following: a) For each n є {10^3, 5x10^3, 10^4, 5x10^4, 10^5}, randomly generate 5 integer arrays of length n. b) Run each of the five comparison sorts you implemented in Step 1 on all the five arrays generated in Step 2.a and record the worst-case actual running time and number of comparisons performed among elements in the input array. #include<iostream> #include<cmath> using namespace std; void displayArray(int a[], int n) { cout<<"\nArray...
Week 2 – Question 2 (10 marks) Describe the three (3) main risks of doing business...
Week 2 – Question 2 Describe the three (3) main risks of doing business in a country. Provide appropriate examples in your response. please answer this by harvard Referencing with no plagiarism. thank you very much.
Antonio made 3 out of 10 free throws in his last basketball game. Estimate the population...
Antonio made 3 out of 10 free throws in his last basketball game. Estimate the population mean that he will make his free throws. Population mean=
A solution is made that is 1.1×10−3 M in Zn(NO3)2 and 0.140 M in NH3. Part...
A solution is made that is 1.1×10−3 M in Zn(NO3)2 and 0.140 M in NH3. Part A After the solution reaches equilibrium, what concentration of Zn2+(aq) remains? Express your answer using two significant figures.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT