Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions abarrientos/javascript/calculadora.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
var __extends, Calculator, UserInterfaceCalculator;

__extends = void 0;
Calculator = void 0;
UserInterfaceCalculator = void 0;

__extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };

return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();

Calculator = (function () {

function Calculator() {
}

Calculator.prototype.sum = function (numberOne, numberTwo) {
return (numberOne + numberTwo);
};

Calculator.prototype.sumNumberList = function (numberList) {
for (var index in numberList) {
this.accumulator += numberList[index];
}
return this.accumulator;
};

Calculator.prototype.substract = function (numberOne, numberTwo) {
return (numberOne - numberTwo);
};

Calculator.prototype.substractNumberList = function (numberList) {
this.accumulator = 0;
for (var index in numberList) {
this.accumulator -= numberList[index];
}
return this.accumulator;
};

Calculator.prototype.product = function (numberOne, numberTwo) {
return (numberOne * numberTwo);
};

Calculator.prototype.divicion = function (numberOne, numberTwo) {
return (numberOne / numberTwo);
};

return Calculator;
}());

UserInterfaceCalculator = (function (_super) {
__extends(UserInterfaceCalculator, _super);

function UserInterfaceCalculator() {
return _super !== null && _super.apply(this, arguments) || this;
}

UserInterfaceCalculator.prototype.leerValorNumerico = function (selector) {
var cadenaOriginal;
var valorNumerico;
cadenaOriginal = document.getElementById(selector).value;
valorNumerico = parseFloat(cadenaOriginal);
return valorNumerico;
};

UserInterfaceCalculator.prototype.imprimirResultado = function (numero) {
document.getElementById("resultado").innerHTML = numero;
};

UserInterfaceCalculator.prototype.creaListaNumeros = function (numeros) {
var arrayListNumberOnString = numeros.split(',');
var arrayListOnFloat = new Array();

for (var index in arrayListNumberOnString) {
arrayListOnFloat.push(parseFloat(arrayListNumberOnString[index]));
}
return arrayListOnFloat;
};

UserInterfaceCalculator.prototype.ejecutarOperacion = function (operacionId) {
var valor1;
var valor2;
var resultado;
var valorDeEntrada;
var arrayList;

valor1 = this.leerValorNumerico("");
valor2 = this.leerValorNumerico("");

switch (true) {
case operacionId === 1:
resultado = this.sum(valor1, valor2);
break;
case operacionId === 2:
valorDeEntrada = document.getElementById("listaDeNumeros").value;
arrayList = this.creaListaNumeros(valorDeEntrada);
resultado = this.sumNumberList(arrayList);
break;
case operacionId === 3:
resultado = this.substract(valor1, valor2);
break;
case operacionId === 4:
valorDeEntrada = document.getElementById("listaDeNumeros").value;
arrayList = this.creaListaNumeros(valorDeEntrada);
resultado = this.substractNumberList(new Array());
break;
case operacionId === 5:
resultado = this.product(valor1, valor2);
break;
}

this.imprimirResultado(resultado);
};

return UserInterfaceCalculator;
}(Calculator));
105 changes: 105 additions & 0 deletions abarrientos/python/calculadora.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

class Calculator(object):
acumulador = None

def __init__(self):
self.acumulador = 0

def suma(self, numero1, numero2):
return (numero1 + numero2)

def sumNumberList(self, numberList=None):
self.acumulador = 0
for valor in numberList:
self.acumulador += valor

return self.acumulador

def subtract(self, numero1, numero2):
return (numero1 - numero2)

def subtractNumberList(self, numberList=None):
self.acumulador = 0
for valor in numberList:
self.acumulador -= valor

return self.acumulador

def product(self, numero1, numero2):
return (numero1 * numero2)

def division(self, numero1, numero2):
return (numero1 / numero2)


class UserInterfaceCalculator(Calculator):

def menu(self):
opcion = None
menu = """

"""
self.imprimir(menu)
opcion = raw_input('escoja una opción numerica:')
return opcion

def leerValorNumerico(self):
valor = None
valor = raw_input('Introdusca un valor numerico:')
return float(valor)

def imprimir(self, valor):
print(valor)

def imprimeAcumulador(self):
print(self.acumulador)

def creaListaNumeros(self, numeros):
numberList = numeros.split(',')
listOnFloat = list()
for numero in numberList:
listOnFloat.append(float(numero))

return listOnFloat

def ejecutaOperacion(self):
valor1 = None
valor2 = None
resultado = None
valorEntrada = None
numberList = list()

operacionID = self.menu()

if operacionID in (2, 4):
valorEntrada = raw_input(
'introdusca una serie de numeros separado por coma'
)
numberList = self.creaListaNumeros(valorEntrada)
else:
valor1 = self.leerValorNumerico()
valor2 = self.leerValorNumerico()

if operacionID is 1:
resultado = self.suma(valor1, valor2)

elif operacionID is 2:
resultado = self.sumNumberList(numberList)

elif operacionID is 3:
resultado = self.subtract(valor1, valor2)

elif operacionID is 4:
resultado = self.subtractNumberList(numberList)

elif operacionID is 5:
resultado = self.product(valor1, valor2)

elif operacionID is 6:
resultado = self.division(valor1, valor2)

self.imprimir(resultado)


calculadora = UserInterfaceCalculator()
calculadora.ejecutaOperacion()