In the folder that is provided with this homework assignment, there are seven files:

  • NumberStack.java: an interface that defines the NumberStack ADT
  • LNode.java: a class that defines a node in linked lists
  • LinkedNumberStack.java: a linked list based implementation for the NumberStack ADT
  • CharStack.java: an array based implementation for a char stack ADT
  • StackApps.java: a class that implements two stack applications using CharStack
  • TestStack.java: a driver class that tests the implementations of your LinkedNumberStack and StackApps classes
  • testNumbers.dat: a binary file that contains 9 test signs and 13 pairs of big integers

Completing the LinkedStack class

In the LinkedNumberStack class, you are required to implement the following methods:

  • push(int v) - This method adds an integer to the top of the stack.
  • pop() - This method removes an element from the top of the stack and returns the element. It throws a RuntimeException "pop attempted on an empty stack" if this operation is attempted on an empty stack.
  • size() - This method returns the number of elements on the stack.

Note that you are only supposed to touch the above three methods. You are NOT allowed to create any other methods, instance variables, or make any changes to methods other than these three methods or files other than "LinkedNumberStack.java". Points will be taken off if you fail to follow this rule.

Code Testing

You are provided with a test driver implemented by "TestStack.java" (Do not make any changes to this file!) so there is no need to write your own.

Once you have completed the methods, you can run the test. You should create a plain text file named "output-P1.txt", copy and paste the output corresponding to Problem 1 (if your code crashes or does not compile, copy and paste the error messages) to this file and save it.

Completing the StackApps class

In this programming question, you are required to implement two methods, evaluateSigns and addBigInteger.

(1) An XOR (eXclusive OR ) operation on two operands return false if they are identical and true otherwise. For instance, both '+' XOR - and - XOR + return + whereas + XOR + and - XOR - return -. Note that we use character + to represent true and - for false. In the StackApps class, the evaluateSigns() method takes a stack of signs (+ and -) and performs the XOR operations on every pair of adjacent signs saved on the stack. It reduces the number of signs by 1 after each round and eventually there is only one sign left. The method returns this sign as the result of the evaluation. In the following example, you will see how the method evaluates the signs.

Figure: see image.

To do this task, you will need to use an auxiliary stack (already created for you) that helps you save the reduced expression. You need to alternate between the signs and the aux stacks because you cannot simply push a sign back into the stack which you just popped off (without using other techniques such as recursion). Do not create any arrays or other data structures in your implementation. Using char variables is okay.

(2) When an integer has more than a certain number of digits, it is represented using scientific notation. The int type itself cannot be used to store numbers with more than 10 digits. In some cases, this may be inconvenient as people usually expect complete numbers and doing big integer computations are inevitable. The addBigInteger() method takes two numbers as CharStacks num1 and num2, and add the number stored in num1 to the one stored in num1, i.e., num1 + num2. For example, when adding 181,749 to 314,739,847, the two stacks and the result stack would look like the following: see image.

In the addBigInteger() method, you are provided with a char stack, stackResult. You will need to perform additions between the two operands and save the result on the result stack. Pay attention to the order of the digits (see above figure for reference). You should compute the sum of the two big numbers digit by digit (from low to high). Be sure to take care of carries. Do not create any arrays or import the java.math.BigInteger library or anything from the Character, Integer, Double, and String classes in your implementation! Same as above, you are only supposed to deal with the digits at the char and int level and make use of stacks.

Note that you are only supposed to touch the above two methods. You are NOT allowed to create any other methods, instance variables, or make any changes to methods other than the two method or files other than "StackApps.java". Points will be taken off if you fail to follow this rule.

Code Testing

In "TestStack.java" (Again, do not make any changes to this file!), a test driver for StackApps is provided. You are also given a data file "testNumbers.dat" that contains 5 decimal numbers that need to be converted to binary and 15 pairs of big integers for subtraction.

Depending on your programming environment, the data file might need to be placed in different folders so that you test driver can read it. For jGRASP, you can leave the data file in the same folder as your java files. For IntelliJ, you should place it in your project folder in which you see directories like out and src, etc.

Once you have completed the evaluateSigns and addBigInteger methods, you can run the test. You should create a plain text file named "output-P2.txt", copy and paste the output corresponding to Problem 2 (if your code crashes or does not compile, copy and paste the error messages) to this file and save it.

Sample output for P1

================ Problem 1 ================
Test 1: size() ==> [Passed]
Expected: 0
Yours: 0

Test 2: pop() ==> [Passed]
Expected: a RuntimeException
Yours: RuntimeException: "pop attempted on an empty stack"

Test 3: push(10) and then isEmpty() ==> [Passed]
Expected: false
Yours: false

Test 4: toString() ==> [Passed]
Expected (from top to bottom): 10
Yours (from top to bottom): 10

Test 5: top() ==> [Passed]
Expected: 10
Yours: 10

Test 6: push(20) and then toString() ==> [Passed]
Expected (from top to bottom): 20 10
Yours (from top to bottom): 20 10

...

Test 23: pop() and then size() ==> [Passed]
Expected: 0
Yours: 0

Total test cases: 23
Correct: 23
Wrong: 0
================ End of Problem 1 ================

Sample output for P2

================ Problem 2 ================
Test 1: evaluateSigns(++) ==> [Passed]
Expected: -
Yours: -

Test 2: evaluateSigns(-+) ==> [Passed]
Expected: +
Yours: +

Test 3: evaluateSigns(+-+) ==> [Passed]
Expected: -
Yours: -

...

Test 21: (348759874975932475974395734967214809124234820 +
984576984576858763295876235) ==> [Passed]
Expected: 348759874975932476958972719544073572420111055
Yours: 348759874975932476958972719544073572420111055

Test 22: (32475982374590873429573249057322356324596378265837465895236
+ 237485963847265873246587364258) ==> [Passed]
Expected: 32475982374590873429573249057559842288443644139084053259494
Yours: 32475982374590873429573249057559842288443644139084053259494

Total test cases: 22
Correct: 22
Wrong: 0
================ End of Problem 2 ================

Starter Codes

// The CharStack class that implements a stack of characters
public class CharStack
{
// instance variables
private char[] m_array;
private int m_index;

// constructor
public CharStack(int cap)
{
m_array = new char[cap];
m_index = 0;
}

// check whether the stack is empty
public boolean isEmpty()
{
if (m_index == 0)
return true;
else
return false;
}

// return the element at the top of the stack
public char top()
{
if (isEmpty())
throw new RuntimeException("top attempted on an empty stack");
else
return m_array[m_index - 1];
}

// push a character onto the stack
public void push(char c)
{
m_array[m_index] = c;
m_index++;
}

// remove and return the element at the top of the stack
public char pop()
{
if (isEmpty())
throw new RuntimeException("pop attempted on an empty stack");
else
{
char c = m_array[m_index - 1];
m_index--;

return c;
}
}

// return the number of elements on the stack
public int size()
{
return m_index;
}

// return a string representation of the stack
@Override
public String toString()
{
String stackContent = "";

for (int i = m_index - 1; i >= 0; i--)
stackContent += m_array[i];

return stackContent;
}
}
// The linked list based implementation for the NumberStack ADT

public class LinkedNumberStack implements NumberStack {
// instance variable
private LNode m_top;

// check whether the stack is empty
public boolean isEmpty() {
if (m_top == null)
return true;
else
return false;
}

// check whether the stack is full
public boolean isFull() {
return false;
}

// return the element at the top of the stack
public int top()
{
if (isEmpty())
throw new RuntimeException( "top attempted on an empty stack" );
else
return m_top.getInfo();
}

// push a value onto the stack
public void push(int v)
{
}

// remove and return the value at the top of the stack
public int pop()
{
}

// return the number of elements on the stack
public int size()
{
}

// return a string representation of the stack
@Override
public String toString()
{
String stackContent = "";
LNode current = m_top;

while (current != null) {
stackContent += current.getInfo() + " ";
current = current.getLink();
}

return stackContent;
}
}
// The LNode class that represents a node in linked lists
// Do not make any changes to this file!
public class LNode
{
// instance variables
/*private*/ int m_info;
/*private*/ LNode m_link;

// constructor
public LNode(int info)
{
m_info = info;
m_link = null;
}

// member methods
public void setLink(LNode link)
{
m_link = link;
}

public LNode getLink()
{
return m_link;
}

public int getInfo()
{
return m_info;
}
}
// The NumberStack interface
// Do not make any changes to this file!
public interface NumberStack
{
boolean isEmpty(); // check whether the stack is empty
boolean isFull(); // check whether the stack is full
int top(); // return the element at the top of the stack
int pop(); // remove and return the element at the top of the stack
void push(int v); // push a value onto the stack
int size(); // return the number of elements on the stack
@Override
String toString(); // return a string representation of the stack
}
// The StackApps class that implements two Stack applications

public class StackApps
{
// evaluate the expression of signs saved in a stack in an xor fashion (see HW specs for details)
// Do not create any arrays or any other structures! Doing so will result in points deduction.
// You can use the auxiliary stack that is created for you in your implementation.
public char evaluateSigns(CharStack signs)
{
}

// add num1 and num2 (both represented as CharStacks), and save the result on a stack
// Do not create any arrays! Do not use any Java libraries to do the calculation.
// Doing so will result in points deduction.
public String addBigInteger(CharStack num1, CharStack num2)
{
}
}
// Test driver for the LinkedNumberStack and StackApps classes
// Do not make any changes to this file!

import java.util.*;
import java.io.*;

public class TestStack
{
public static void main(String[] args)
{
System.out.println("================ Problem 1 ================");
TestP1();
System.out.println("================ End of Problem 1 ================nn");

System.out.print("Press any key to test Problem 2...");
try
{
System.in.read();
}
catch (Exception e)
{
e.printStackTrace();
}

System.out.println("================ Problem 2 ================");
TestP2();
System.out.println("================ End of Problem 2 ================");
}

public static void TestP1()
{
NumberStack myStack = new LinkedNumberStack();
int numPassedTests = 0;
int numTotalTests = 0;
String testResult;

// Test 1
numTotalTests++;
int iReturn = -1;
testResult = "[Failed]";
String eMsg = "N/A";
try
{
iReturn = myStack.size();

if (iReturn == 0)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": size() ==> " + testResult + "n Expected: 0" );
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 2
numTotalTests++;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();
}
catch (RuntimeException e)
{
if (!(e instanceof NullPointerException))
{
numPassedTests++;
testResult = "[Passed]";
}

eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() ==> " + testResult + "n Expected: a RuntimeException");
System.out.println(" Yours: " + eMsg + "n");

// Test 3
numTotalTests++;
boolean bReturn = false;
testResult = "[Failed]";
eMsg = "N/A";
try
{
myStack.push(10);
bReturn = myStack.isEmpty();

if (bReturn == false)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": push(10) and then isEmpty() ==> " + testResult + "n Expected: false");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + bReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 4
numTotalTests++;
String sReturn = myStack.toString();

if (sReturn.equals("10 "))
{
numPassedTests++;
testResult = "[Passed]";
}
else
testResult = "[Failed]";

System.out.println("Test " + numTotalTests + ": toString() ==> " + testResult + "n Expected (from top to bottom): 10 ");
System.out.println(" Yours (from top to bottom): " + sReturn + "n");

// Test 5
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.top();

if (iReturn == 10)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": top() ==> " + testResult + "n Expected: 10");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 6
numTotalTests++;
sReturn = "";
testResult = "[Failed]";
eMsg = "N/A";
try
{
myStack.push(20);
sReturn = myStack.toString();

if (sReturn.equals("20 10 "))
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": push(20) and then toString() ==> " + testResult + "n Expected (from top to bottom): 20 10 ");
if (eMsg.equals("N/A"))
System.out.println(" Yours (from top to bottom): " + sReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 7
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.top();

if (iReturn == 20)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": top() ==> " + testResult + "n Expected: 20");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 8
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();

if (iReturn == 20)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() ==> " + testResult + "n Expected: 20");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 9
numTotalTests++;
sReturn = myStack.toString();

if (sReturn.equals("10 "))
{
numPassedTests++;
testResult = "[Passed]";
}
else
testResult = "[Failed]";

System.out.println("Test " + numTotalTests + ": toString() ==> " + testResult + "n Expected (from top to bottom): 10 ");
System.out.println(" Yours (from top to bottom): " + sReturn + "n");

// Test 10
numTotalTests++;
sReturn = "";
testResult = "[Failed]";
eMsg = "N/A";
try
{
myStack.push(30);
myStack.push(40);
myStack.push(50);
sReturn = myStack.toString();

if (sReturn.equals("50 40 30 10 "))
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": push(30), push(40), push(50), and then toString() ==> " + testResult + "n Expected (from top to bottom): 50 40 30 10 ");
if (eMsg.equals("N/A"))
System.out.println(" Yours (from top to bottom): " + sReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 11
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.size();

if (iReturn == 4)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": size() ==> " + testResult + "n Expected: 4" );
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 12
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();
iReturn = myStack.top();

if (iReturn == 40)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() and then top() ==> " + testResult + "n Expected: 40");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 13
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();
iReturn = myStack.size();

if (iReturn == 2)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() and then size() ==> " + testResult + "n Expected: 2");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 14
numTotalTests++;
sReturn = "";
testResult = "[Failed]";
eMsg = "N/A";
try
{
myStack.push(20);
sReturn = myStack.toString();

if (sReturn.equals("20 30 10 "))
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": push(20) and then toString() ==> " + testResult + "n Expected (from top to bottom): 20 30 10 ");
if (eMsg.equals("N/A"))
System.out.println(" Yours (from top to bottom): " + sReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 15
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.size();

if (iReturn == 3)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": size() ==> " + testResult + "n Expected: 3" );
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 16
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();
iReturn = myStack.pop();
iReturn = myStack.top();

if (iReturn == 10)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() twice and then top() ==> " + testResult + "n Expected: 10");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 17
numTotalTests++;
sReturn = "";
testResult = "[Failed]";
eMsg = "N/A";
try
{
sReturn = myStack.toString();

if (sReturn.equals("10 "))
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": toString() ==> " + testResult + "n Expected (from top to bottom): 10 ");
if (eMsg.equals("N/A"))
System.out.println(" Yours (from top to bottom): " + sReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 18
numTotalTests++;
bReturn = false;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();
bReturn = myStack.isEmpty();

if (bReturn == true && iReturn == 10)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() and then isEmpty() ==> " + testResult + "n Expected: 10, true");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + ", " + bReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 19
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.size();

if (iReturn == 0)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": size() ==> " + testResult + "n Expected: 0" );
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 20
numTotalTests++;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();
}
catch (RuntimeException e)
{
if (!(e instanceof NullPointerException))
{
numPassedTests++;
testResult = "[Passed]";
}

eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() ==> " + testResult + "n Expected: a RuntimeException");
System.out.println(" Yours: " + eMsg + "n");

// Test 21
numTotalTests++;
sReturn = "";
testResult = "[Failed]";
eMsg = "N/A";
try
{
myStack.push(70);
sReturn = myStack.toString();

if (sReturn.equals("70 "))
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": push(70) and then toString() ==> " + testResult + "n Expected (from top to bottom): 70 ");
if (eMsg.equals("N/A"))
System.out.println(" Yours (from top to bottom): " + sReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 22
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.top();

if (iReturn == 70)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": top() ==> " + testResult + "n Expected: 70");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

// Test 23
numTotalTests++;
iReturn = -1;
testResult = "[Failed]";
eMsg = "N/A";
try
{
iReturn = myStack.pop();
iReturn = myStack.size();

if (iReturn == 0)
{
numPassedTests++;
testResult = "[Passed]";
}
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.println("Test " + numTotalTests + ": pop() and then size() ==> " + testResult + "n Expected: 0");
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + iReturn + "n");
else
System.out.println(" Yours: " + eMsg + "n");

System.out.println("Total test cases: " + numTotalTests + "nCorrect: " + numPassedTests + "nWrong: " + (numTotalTests - numPassedTests));
}

public static void TestP2()
{
try
{
ObjectInputStream in = new ObjectInputStream(new FileInputStream("testNumbers.dat"));
StackApps myApps = new StackApps();
ArrayList results = new ArrayList<>();
ArrayList numbers = new ArrayList();
results = (ArrayList)in.readObject();
numbers = (ArrayList)in.readObject();

char cr;
String sr;
String eMsg;
String currentLine;
int numPassedTests = 0;
int numTotalTests = 0;

for (int i = 0; i < 9; i++)
{
numTotalTests++;
currentLine = numbers.get(i);
CharStack signs = new CharStack(64); // stack used to store the signs

// push digits of number 1 onto stack
for (int j = 0; j < currentLine.length(); j++)
signs.push(currentLine.charAt(j));

String strStack = signs.toString();

cr = ' ';
eMsg = "N/A";
try
{
cr = myApps.evaluateSigns(signs);
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.print("Test " + numTotalTests + ": evaluateSigns(" + strStack + ") ==> ");

if (cr == results.get(i).charAt(0))
{
System.out.println("[Passed]");
numPassedTests++;
}
else
System.out.println("[Failed]");

System.out.println(" Expected: " + results.get(i));
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + cr + "n");
else
System.out.println(" Yours: " + eMsg + "n");
}

for (int i = 9; i < numbers.size(); i++)
{
numTotalTests++;
currentLine = numbers.get(i);
String[] operands = currentLine.split(" ");
CharStack num1 = new CharStack(64); // stack used to store number 1
CharStack num2 = new CharStack(64); // stack used to store number 2

// push digits of number 1 onto stack
for (int j = 0; j < operands[0].length(); j++)
num1.push(operands[0].charAt(j));

// push digits of number 2 onto stack
for (int j = 0; j < operands[1].length(); j++)
num2.push(operands[1].charAt(j));

sr = "";
eMsg = "N/A";
try
{
sr = myApps.addBigInteger(num1, num2);
}
catch (RuntimeException e)
{
eMsg = "RuntimeException - "" + e.getMessage() + """;
}

System.out.print("Test " + numTotalTests + ": (" + operands[0] + " + " + operands[1] + ") ==> ");

if (sr.equals(results.get(i)))
{
System.out.println("[Passed]");
numPassedTests++;
}
else
System.out.println("[Failed]");

System.out.println(" Expected: " + results.get(i));
if (eMsg.equals("N/A"))
System.out.println(" Yours: " + sr + "n");
else
System.out.println(" Yours: " + eMsg + "n");
}

System.out.println("Total test cases: " + numTotalTests + "nCorrect: " + numPassedTests + "nWrong: " + (numTotalTests - numPassedTests));
}
catch (Exception e)
{
System.out.println("Error occurred: " + e.getMessage());
}
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.