Created
October 10, 2012 03:46
-
-
Save delucas/3863043 to your computer and use it in GitHub Desktop.
UNLaM - TW1 - Billetera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ar.edu.unlam.tallerweb.billetera; | |
public class BilleteException extends Exception { | |
private static final long serialVersionUID = 8656459465486574L; | |
public BilleteException(String message){ | |
super(message); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ar.edu.unlam.tallerweb.billetera; | |
import java.math.BigDecimal; | |
public class Billete { | |
private BigDecimal monto; | |
private String moneda; | |
public Billete(BigDecimal monto, String moneda) { | |
this.monto = monto; | |
this.moneda = moneda; | |
} | |
public Billete sumar (Billete otro) throws BilleteException { | |
if (this.moneda.equals(otro.moneda)){ | |
return new Billete (this.monto.add(otro.monto), this.moneda); | |
} else{ | |
throw new BilleteException("No se pueden sumar Billetes de diferente Moneda"); | |
} | |
} | |
public BigDecimal getMonto() { | |
return this.monto; | |
} | |
public String getMoneda() { | |
return this.moneda; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ar.edu.unlam.tallerweb.billetera; | |
import java.math.BigDecimal; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class BilleteraTest { | |
@Test | |
public void testQueSePuedaSumar() throws BilleteException{ | |
Billete b1 = new Billete(new BigDecimal("1"),"pesos"); | |
Billete b2 = new Billete(new BigDecimal("1"),"pesos"); | |
Billete b3 = b1.sumar(b2); | |
Assert.assertEquals(new BigDecimal("2"), b3.getMonto()); | |
Assert.assertEquals("pesos", b3.getMoneda()); | |
} | |
@Test(expected=BilleteException.class) | |
public void testQueNoSePuedaSumar() throws BilleteException{ | |
Billete b1 = new Billete(new BigDecimal("1"),"pesos"); | |
Billete b2 = new Billete(new BigDecimal("1"),"dolares"); | |
b1.sumar(b2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment