Algorithms and OOD (CSC 207 2014S) : EBoards

CSC 207 2014S: Extra Session, Week 3



Can you help me think through the last question? I split the string into parts. How would I then change a string into a mathemical operator?

String[] stuff = input.split(" ");
BigInteger result = new BigInteger(stuff[0]);
for (int i = 1; i < stuff.length; i += 2) 
    String operator = stuff[i];
    BigInteger operand = new BigInteger(stuff[i+1]);
    // Case 1: Addition
    if (operator.equals("+"))
        result = result.add(operand);
      } // "+"
    // Otherwise, it's not a valid operator
        throw new Exception("Invalid operator: " + operator);
      } // if not a valid operator
  } // for

How can we do a better job of going from our concept to our implementation?

I'm not sure.

How upset are you that our CSV code crashes on invalid inputs?

Not very. I told you to assume valid inputs.

Can we watch Sam fail to write the CSV program?


Thirty minutes later, we had a working program, which does some checking of input.

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.