/**
 * @author Daniel Casner <daniel.t.casner@ieee.org>
 * 
 * This javascript creates a series of simple arithmetic expressions represented
 * in different bases such that:
 *  # The hour in 24 hour time format
 *  # The tens place for minute
 *  # The ones place for minute
 *  # The tens place for second
 *  # The ones place for second
 *  
 *  This requires the baseconvert.js javascript module as well.
 */

/**
 * An object to represent a simple arithmetic expression in the
 * given base. It generates two random operands in the range 0 to
 * maxOperand, a random arithmetic operator (+, -, *, /) and represents 
 * the expression including result in the specified base.
 * 
 */
function Expression(base, maxOperand) {
	this.radix = base;
	this.op1 = Math.ceil(Math.random() * maxOperand);
	this.op2 = Math.ceil(Math.random() * maxOperand);
	this.operator = '';
	this.result = 0;
	
	switch(Math.floor(Math.random() * 4)) {
	case 0:
		this.operator = '+';
		this.result   = this.op1 + this.op2;
		break;
	case 1:
		this.operator = '-';
		this.result   = this.op1 - this.op2;
		break;
	case 2:
		this.operator = '*';
		this.result   = this.op1 * this.op2;
		break;
	case 3:
		this.operator = '/';
		this.result   = this.op1 / this.op2;
		break;
	}
	
	this.toString = function() {
		return this.op1.toString(this.radix) + ' ' + this.operator + ' ' +
		         this.op2.toString(this.radix) + ' = ' +
					this.result.toString(this.radix);
	}
}


function makeClock(dateObj) {
   var hour = dateObj.getHours();
	if(hour > 1) hour = new Expression(hour, 20);
	
	var minuteTens = Math.floor(dateObj.getMinutes() / 10);
	if(minuteTens > 1) minuteTens = new Expression(minuteTens, 20);
	
	var minuteOnes = Math.floor(dateObj.getMinutes() % 10);
	if(minuteOnes > 1) minuteOnes = new Expression(minuteOnes, 20);
	
	var secondTens = Math.floor(dateObj.getSeconds() / 10);
	if(secondTens > 1) secondTens = new Expression(secondTens, 20);

	var secondOnes = Math.floor(dateObj.getSeconds() % 10);
	if(secondOnes > 1) secondOnes = new Expression(secondOnes, 20);
	
	return hour.toString() + '<br />\n:<br />\n' +
	       minuteTens.toString() + '<br />\n' + minuteOnes.toString() + '<br />\n:<br />\n' +
			 secondTens.toString() + '<br />\n' + secondOnes.toString() + '<br />\n';
}