Пример #1
0
 @Test
 public void testReduceMoneyDifferentCurrency() {
   Bank bank = new Bank();
   bank.addRate("CHF", "USD", 2);
   Money result = bank.reduce(Money.franc(2), "USD");
   assertEquals(Money.dollar(1), result);
 }
Пример #2
0
  public void newGame() {

    gameObject1.clear();
    gameObject2.clear();
    gameObject3.clear();
    gameObject4.clear();

    gameObjectadd();
    timer.resetTimer();
    score1 = 0;
    score2 = 0;
    totalWinner = 0;
    winner = 0;
    money.randomize();
    state = 1;
    round = 0;
    choose = "Nope";
    choose2 = "Nope";
    newMoney(scaledMoney, money.drawUpdate(money.vals[0]));
    newMoney(Money1, score11.drawUpdate(0));
    newMoney(Money2, score22.drawUpdate(0));
    newMoney(scaledTimer, timer.drawUpdate());

    score11.setBitmap(Money1.get(0), Money1.get(1));
    score22.setBitmap(Money2.get(0), Money2.get(1));
    money.setBitmap(scaledMoney.get(0), scaledMoney.get(1));
    timer.setBitmap(scaledTimer.get(0), scaledTimer.get(1));
  }
Пример #3
0
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    scaleFactorX = getWidth() / (WIDTH * 1.f);
    scaleFactorY = getHeight() / (HEIGHT * 1.f);

    createPics();

    scaledMoney.add(BitmapFactory.decodeResource(getResources(), R.drawable.money));
    scaledMoney.add(BitmapFactory.decodeResource(getResources(), R.drawable.kingword));
    Money1.add(BitmapFactory.decodeResource(getResources(), R.drawable.money));
    Money1.add(BitmapFactory.decodeResource(getResources(), R.drawable.kingword));
    Money2.add(BitmapFactory.decodeResource(getResources(), R.drawable.money));
    Money2.add(BitmapFactory.decodeResource(getResources(), R.drawable.kingword));
    scaledTimer.add(BitmapFactory.decodeResource(getResources(), R.drawable.civilian));
    scaledTimer.add(BitmapFactory.decodeResource(getResources(), R.drawable.captain));

    setupVar();

    newMoney(scaledMoney, money.drawUpdate(money.vals[0]));
    newMoney(Money1, score11.drawUpdate(0));
    newMoney(Money2, score22.drawUpdate(0));
    newMoney(scaledTimer, timer.drawUpdate());

    score11.setBitmap(Money1.get(0), Money1.get(1));
    score22.setBitmap(Money2.get(0), Money2.get(1));
    money.setBitmap(scaledMoney.get(0), scaledMoney.get(1));
    timer.setBitmap(scaledTimer.get(0), scaledTimer.get(1));

    thread = new MainThread(getHolder(), this);
    // we can safely start the game loop
    thread.setRunning(true);
    thread.start();
  }
Пример #4
0
 @Test
 public void testCheckInputFail() {
   try {
     Money.checkInput("1xyz2");
     fail("Expected Exception not thrown!");
   } catch (ParseException pe) {
   }
   try {
     Money.checkInput("1.234'00");
     fail("Expected Exception not thrown!");
   } catch (ParseException pe) {
   }
   try {
     Money.checkInput("1'234,00");
     fail("Expected Exception not thrown!");
   } catch (ParseException pe) {
   }
   try {
     Money.checkInput("1,234.00");
     fail("Expected Exception not thrown!");
   } catch (ParseException pe) {
   }
   try {
     Money.checkInput("1,234,00");
     fail("Expected Exception not thrown!");
   } catch (ParseException pe) {
   }
 }
Пример #5
0
  /**
   * Builds a QIF entry representing this transaction
   *
   * @return String QIF representation of this transaction
   */
  public String toQIF() {
    final String newLine = "\n";

    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(GnuCashApplication.getAppContext());

    // all transactions are double transactions
    String splitAccountFullName = QifHelper.getImbalanceAccountName(mAmount.getCurrency());
    if (mDoubleEntryAccountUID != null && mDoubleEntryAccountUID.length() > 0) {
      splitAccountFullName = accountsDbAdapter.getFullyQualifiedAccountName(mDoubleEntryAccountUID);
    }

    StringBuffer transactionQifBuffer = new StringBuffer();
    transactionQifBuffer
        .append(QifHelper.DATE_PREFIX)
        .append(QifHelper.formatDate(mTimestamp))
        .append(newLine);
    transactionQifBuffer.append(QifHelper.MEMO_PREFIX).append(mName).append(newLine);

    transactionQifBuffer
        .append(QifHelper.SPLIT_CATEGORY_PREFIX)
        .append(splitAccountFullName)
        .append(newLine);
    if (mDescription != null && mDescription.length() > 0) {
      transactionQifBuffer.append(QifHelper.SPLIT_MEMO_PREFIX).append(mDescription).append(newLine);
    }
    transactionQifBuffer
        .append(QifHelper.SPLIT_AMOUNT_PREFIX)
        .append(mAmount.asString())
        .append(newLine);
    transactionQifBuffer.append(QifHelper.ENTRY_TERMINATOR).append(newLine);

    accountsDbAdapter.close();
    return transactionQifBuffer.toString();
  }
Пример #6
0
 @Test
 public void testReduceSum() {
   Expression sum = new Sum(Money.dollar(3), Money.dollar(4));
   Bank bank = new Bank();
   Money result = bank.reduce(sum, "USD");
   assertEquals(Money.dollar(7), result);
 }
 @NotNull
 RepaymentSummary add(RepaymentSummary other) {
   return new RepaymentSummary(
       remainingDebt,
       totalInterest.plus(other.totalInterest),
       totalRepayments.plus(other.totalRepayments),
       totalRates.plus(other.totalRates));
 }
Пример #8
0
 public boolean equals(Object anObject) {
   if (isZero()) if (anObject instanceof IMoney) return ((IMoney) anObject).isZero();
   if (anObject instanceof Money) {
     Money aMoney = (Money) anObject;
     return aMoney.currency().equals(currency()) && amount() == aMoney.amount();
   }
   return false;
 }
Пример #9
0
 @Test
 public void testAddition() {
   Money five = Money.dollar(5);
   Expression sum = five.plus(five);
   Bank bank = new Bank();
   Money reduced = bank.reduce(sum, "USD");
   assertEquals(Money.dollar(10), reduced);
 }
 @Override
 public int hashCode() {
   int result = remainingDebt.hashCode();
   result = 31 * result + totalInterest.hashCode();
   result = 31 * result + totalRepayments.hashCode();
   result = 31 * result + totalRates.hashCode();
   return result;
 }
Пример #11
0
 @Test
 public void testEquality() {
   assertTrue(Money.dollar(5).equals(Money.dollar(5)));
   assertFalse(Money.dollar(6).equals(Money.dollar(5)));
   assertTrue(Money.franc(5).equals(Money.franc(5)));
   assertFalse(Money.franc(6).equals(Money.franc(5)));
   assertFalse(Money.franc(5).equals(Money.dollar(5)));
 }
 @NotNull
 RepaymentSummary add(MonthlyRepayment other) {
   return new RepaymentSummary(
       remainingDebt,
       totalInterest.plus(other.interest()),
       totalRepayments.plus(other.repayment()),
       totalRates.plus(other.monthlyRate()));
 }
Пример #13
0
  public void testMixedAddition() {
    Expression fiveBucks = Money.dollar(5);
    Expression tenFrancs = Money.franc(10);

    Bank bank = new Bank();
    bank.addRate("CHF", "USD", 2);
    Money result = bank.reduce(fiveBucks.plus(tenFrancs), "USD");
    assertEquals(Money.dollar(10), result);
  }
Пример #14
0
  @Test
  public void testPlusReturnsSum() {
    Money five = Money.dollar(5);
    Expression result = five.plus(five);
    Sum sum = (Sum) result;

    assertEquals(five, sum.augend);
    assertEquals(five, sum.addend);
  }
Пример #15
0
  @Test
  public void testSumTimes() {
    Expression fiveBucks = Money.dollar(5);
    Expression tenFranks = Money.franc(10);
    Bank bank = new Bank();
    bank.addRate("CHF", "USD", 2);

    Expression sum = new Sum(fiveBucks, tenFranks).times(2);
    Money result = bank.reduce(sum, "USD");
    assertEquals(Money.dollar(20), result);
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    RepaymentSummary that = (RepaymentSummary) o;

    if (!remainingDebt.equals(that.remainingDebt)) return false;
    if (!totalInterest.equals(that.totalInterest)) return false;
    if (!totalRepayments.equals(that.totalRepayments)) return false;
    return totalRates.equals(that.totalRates);
  }
 /** add(Money value) binary operator returns sum of object plus value */
 public Money add(Money value) {
   Money result = new Money();
   result.cents = cents + value.cents;
   result.dollars = dollars + value.dollars;
   // Only need to check if cents is greater than 100 since the
   // largest value that can result from an addition is 198
   if (result.cents >= 100) {
     ++result.dollars;
     result.cents -= 100;
   }
   return result;
 }
Пример #18
0
 @Override
 public boolean equals(Object o) {
   if (o == null) {
     return false;
   }
   if (this == o) {
     return true;
   }
   if (!(o instanceof Money)) {
     return false;
   }
   Money money = (Money) o;
   return amount == money.amount && currency().equals(money.currency());
 }
Пример #19
0
  @Test
  public void testSubstractMoney() {
    Money money = new Money(1.1);
    Money moneyOne = new Money(1.0);
    Money moneyPointOne = new Money(0.1);
    Money moneyMinusOne = new Money(-1.0);

    money.subtractMoney(moneyOne);
    assertEquals(0.1, money.getAmount(), 0.0001);
    money.subtractMoney(moneyPointOne);
    assertEquals(0.0, money.getAmount(), 0.0001);
    // Subtracting a negative amount does not lead to positive result !!!
    // money.addMoney(moneyMinusOne);
    // assertEquals(1.0, money.getAmount(), 0.0001);
  }
Пример #20
0
  @Override
  public ManagerPanel getById(int userId) throws DbException {
    PreparedStatement ps = null;
    ResultSet rs = null;
    ManagerPanel managerPanel = null;
    try {
      managerPanel = new ManagerPanel();

      prepareConnection();

      ps = connection.prepareStatement(MANAGER_SELECT_BY_ID);
      ps.setInt(1, userId);
      rs = ps.executeQuery();

      rs.next();
      Money finresult = Money.dollars(rs.getDouble("summaryfinresult"));
      managerPanel.setSummaryFinRes(finresult);

    } catch (SQLException e) {
      throw new DbException("Can't execute SQL = '" + MANAGER_SELECT_BY_ID + "'", e);
    } finally {
      daoHelper.closeDataBaseEntities(ps, rs, connection);
    }
    return managerPanel;
  }
Пример #21
0
  /**
   * Converts transaction to XML DOM corresponding to OFX Statement transaction and returns the
   * element node for the transaction. The Unique ID of the account is needed in order to properly
   * export double entry transactions
   *
   * @param doc XML document to which transaction should be added
   * @param accountUID Unique Identifier of the account which called the method.
   * @return Element in DOM corresponding to transaction
   */
  public Element toOfx(Document doc, String accountUID) {
    Element transactionNode = doc.createElement("STMTTRN");
    Element type = doc.createElement("TRNTYPE");
    type.appendChild(doc.createTextNode(mType.toString()));
    transactionNode.appendChild(type);

    Element datePosted = doc.createElement("DTPOSTED");
    datePosted.appendChild(doc.createTextNode(OfxExporter.getOfxFormattedTime(mTimestamp)));
    transactionNode.appendChild(datePosted);

    Element dateUser = doc.createElement("DTUSER");
    dateUser.appendChild(doc.createTextNode(OfxExporter.getOfxFormattedTime(mTimestamp)));
    transactionNode.appendChild(dateUser);

    Element amount = doc.createElement("TRNAMT");
    amount.appendChild(doc.createTextNode(mAmount.toPlainString()));
    transactionNode.appendChild(amount);

    Element transID = doc.createElement("FITID");
    transID.appendChild(doc.createTextNode(mTransactionUID));
    transactionNode.appendChild(transID);

    Element name = doc.createElement("NAME");
    name.appendChild(doc.createTextNode(mName));
    transactionNode.appendChild(name);

    if (mDescription != null && mDescription.length() > 0) {
      Element memo = doc.createElement("MEMO");
      memo.appendChild(doc.createTextNode(mDescription));
      transactionNode.appendChild(memo);
    }

    if (mDoubleEntryAccountUID != null && mDoubleEntryAccountUID.length() > 0) {
      Element bankId = doc.createElement("BANKID");
      bankId.appendChild(doc.createTextNode(OfxExporter.APP_ID));

      // select the proper account as the double account
      String doubleAccountUID =
          mDoubleEntryAccountUID.equals(accountUID) ? mAccountUID : mDoubleEntryAccountUID;

      Element acctId = doc.createElement("ACCTID");
      acctId.appendChild(doc.createTextNode(doubleAccountUID));

      Element accttype = doc.createElement("ACCTTYPE");
      AccountsDbAdapter acctDbAdapter = new AccountsDbAdapter(GnuCashApplication.getAppContext());
      OfxAccountType ofxAccountType =
          Account.convertToOfxAccountType(acctDbAdapter.getAccountType(doubleAccountUID));
      accttype.appendChild(doc.createTextNode(ofxAccountType.toString()));
      acctDbAdapter.close();

      Element bankAccountTo = doc.createElement("BANKACCTTO");
      bankAccountTo.appendChild(bankId);
      bankAccountTo.appendChild(acctId);
      bankAccountTo.appendChild(accttype);

      transactionNode.appendChild(bankAccountTo);
    }

    return transactionNode;
  }
Пример #22
0
  @Test
  public void testDollarMultiplication() {
    Money five = Money.dollar(5);
    assertEquals(Money.dollar(5), five);
    assertEquals(Money.dollar(10), five.times(2));

    assertEquals(Money.dollar(5), five);
    assertEquals(Money.dollar(15), five.times(3));
  }
Пример #23
0
  @Test
  public void testFrancMultiplication() {
    Money five = Money.franc(5);
    assertEquals(Money.franc(5), five);
    assertEquals(Money.franc(10), five.times(2));

    assertEquals(Money.franc(5), five);
    assertEquals(Money.franc(15), five.times(3));
  }
Пример #24
0
 /**
  * Specifies the price of the line item. Required.
  *
  * @param price of the line item, {@code price.amount() <= Integer.MAX_VALUE}
  * @throws IllegalStateException if the price is already set
  * @throws IllegalArgumentException if {@code price.amount() > Integer.MAX_VALUE}
  * @return this builder
  */
 public Builder price(Money price) {
   if (this.price != null) alreadySet("price");
   if (price.amount() > Integer.MAX_VALUE) {
     throw new IllegalArgumentException("price.amount() > Integer.MAX_VALUE");
   }
   this.price = price;
   return this;
 }
 /**
  * subtract(Money value) binary operator returns the difference between object and value returns
  * an error if value is larger than the object calling the method
  */
 public Money subtract(Money value) {
   Money result = new Money();
   // Find the total cents values for the subtrahend (value) and the minuend (this), and compare
   // them to make sure
   // that the subtrahend is smaller than the minuend.
   long myCentsAmount = (this.dollars * 100) + this.cents;
   long valueCentsAmount = (value.dollars * 100) + value.cents;
   long differenceBetween = myCentsAmount - valueCentsAmount;
   if (differenceBetween < 0) { // Subtraction will result in a negative money value
     System.out.println(
         "! ERROR: Subtraction can't result in a negative Money value! "
             + "Setting dollars and cents to default values of 0.");
   } else { // Proper values for subtraction
     result.dollars = differenceBetween / 100;
     result.cents = differenceBetween % 100;
   }
   return result;
 }
  @Test
  public void willLimitBidToMaximum() throws Exception {
    sniper.bidAccepted(maximumBid.subtract(new Money(1)));

    new Verifications() {
      {
        auction.bid(maximumBid);
      }
    };
  }
Пример #27
0
public enum AccountType {
  SAVINGS(
      "savings", Money.$(200f), Money.$(200f), null, Money.$(1.5f), Money.$(2.5f), Money.$(0.5f)),
  CHECKING("checking", Money.$(200f), Money.$(200f), null, Money.$(0), Money.$(2.50f), Money.$(0));

  private final String description;

  private EnumMap<WithdrawType, Money> limits;
  private EnumMap<WithdrawType, Money> fees;

  private AccountType(
      String description,
      Money limitBankMachine,
      Money limitInteracMachine,
      Money limitPersonalCheck,
      Money feesBankMachine,
      Money feesInteracMachine,
      Money feesPersonalCheck) {
    this.description = description;
    limits = new EnumMap<WithdrawType, Money>(WithdrawType.class);

    limits.put(WithdrawType.ATM, limitBankMachine);
    limits.put(WithdrawType.INTERAC, limitInteracMachine);
    limits.put(WithdrawType.PERSONAL_CHECK, limitPersonalCheck);

    fees = new EnumMap<WithdrawType, Money>(WithdrawType.class);
    fees.put(WithdrawType.ATM, feesBankMachine);
    fees.put(WithdrawType.INTERAC, feesInteracMachine);
    fees.put(WithdrawType.PERSONAL_CHECK, feesPersonalCheck);
  }

  @Override
  public String toString() {
    return description;
  }

  public Money limitFor(WithdrawType withdrawType) {
    return limits.get(withdrawType);
  }

  public Money feesFor(WithdrawType withdrawType) {
    return fees.get(withdrawType);
  }

  public static boolean isNoLimit(Money limit) {
    return limit == null;
  }
}
Пример #28
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   in.defaultReadObject();
   if (price == null) throw new AssertionError("missing price");
   if (price.amount() > Integer.MAX_VALUE) {
     throw new AssertionError("price.amount() > Integer.MAX_VALUE");
   }
   if (description != null && description.length() > MAX_DESCRIPTION_LENGTH) {
     throw new AssertionError("description.length() > 140");
   }
 }
Пример #29
0
  private static void testingWhenPoundsAndPence() {
    Money m1, m2, m3, m4;

    m1 = new Money(9, 64); // valid False
    m2 = new Money(0, 0); // valid true
    m3 = new Money(99, 164); // valid true
    m4 = new Money(100, 10); // valid false

    Money[] mAr = new Money[] {m1, m2, m3, m4};

    for (Money money : mAr) {
      // System.out.println(money.getValidMoney());

      // System.out.println(money.getCurrentMoney());
      // System.out.println("\r\n");
    }

    m1.addMoney(1, 50);
    System.out.println(m1.toString());
  }
  @Test
  public void willLimitBidToMaximum() throws Exception {
    context.checking(
        new Expectations() {
          {
            exactly(1).of(auction).bid(maximumBid);
          }
        });

    sniper.bidAccepted(maximumBid.subtract(new Money(1)));
  }