public void createBankAccount() { Scanner scanner = new Scanner(System.in); System.out.println("Enter first name: "); String firstName = scanner.nextLine(); System.out.println("Enter last name: "); String lastName = scanner.nextLine(); System.out.println("Enter age: "); int age = Integer.parseInt(scanner.nextLine()); System.out.println("Enter initial balance: "); double balance = Double.parseDouble(scanner.nextLine()); System.out.println("Enter account number: "); long accountNumber = Long.parseLong(scanner.nextLine()); System.out.println("Enter interest type: "); String intType = scanner.nextLine(); System.out.println("Enter interest value: "); Double intValue = Double.parseDouble(scanner.nextLine()); BankAccountOwner owner = new BankAccountOwner(firstName, lastName, age); Interest interest = new Interest(intValue, intType); BankAccount account = new BankAccount(accountNumber, owner, balance, interest); bank.add(account); bank.get(accountNumber).getHistory().add("Created a bank account"); scanner.close(); }
@Override public void openDepositAccount(double amount, int period, Bank myBank) throws NotEnoughMoneyException, UnknownProductException { if (amount < this.amountOfMoney) { if (this.myDeposits.isEmpty()) { this.myDeposits.add(Deposit.makeNewDeposit(period, amount)); myBank.addDeposit(myDeposits.get(0)); } else { for (int i = 0; i < this.myDeposits.size(); i++) { if (this.myDeposits.get(i).getPeriod() == period) { myBank.addFunds(amount); myDeposits.get(i).setEffective(myDeposits.get(i).getEffective() + amount); break; } else { Deposit newDeposit = Deposit.makeNewDeposit(period, amount); this.myDeposits.add(newDeposit); myBank.addDeposit(newDeposit); } } } this.setAmountOfMoney(this.getAmountOfMoney() - amount); } else { throw new NotEnoughMoneyException("We kindly ask you to leave the building."); } }
@Test public void failedTransaction2() throws ExecutionException, InterruptedException { Stage stage = createStage(); Bank bank = Actor.getReference(Bank.class, "jimmy"); Inventory inventory = Actor.getReference(Inventory.class, "jimmy"); Store store = Actor.getReference(Store.class, "all"); bank.increment(15).join(); fakeSync.put("proceed", "ok"); // this item is invalid but the bank balance is decreased first. store.buyItem(bank, inventory, "candy", 10).join(); store.buyItem(bank, inventory, "chocolate", 1).join(); try { store.buyItem(bank, inventory, "ice cream", 50).join(); fail("expecting an exception"); } catch (CompletionException ex) { System.out.println(ex.getCause().getMessage()); } // the bank credits must be restored. eventually(() -> assertEquals((Integer) 4, bank.getBalance().join())); // no items were given eventually(() -> assertEquals(2, inventory.getItems().join().size())); dumpMessages(); }
// decrease this players cash by amount // return if you owe some resting standing (you didn't pay fully) public Long giveMoney(Long amount) { if (this.cash > amount) { this.cash -= amount; StdOut.println( this.name + " paid " + Bank.moneyEuro(amount) + " (current cash " + Bank.moneyEuro(this.cash) + ")"); return 0L; } else { Long owed = amount - this.cash; StdOut.println( this.name + " paid " + Bank.moneyEuro(this.cash) + " (owed " + Bank.moneyEuro(owed) + ")"); this.cash = 0L; return owed; } }
public void transferMoney() throws InsufficientFundsException, NonExistingBankAccountException { Scanner scanner = new Scanner(System.in); System.out.println("Enter origin account number: "); long originAccountNumber = Long.parseLong(scanner.nextLine()); System.out.println("Enter destination account number: "); long destinationAccountNumber = Long.parseLong(scanner.nextLine()); System.out.println("Enter amount of money you want to transfer: "); double money = Double.parseDouble(scanner.nextLine()); scanner.close(); if (bank.get(originAccountNumber) == null || bank.get(destinationAccountNumber) == null) { throw new NonExistingBankAccountException("Bank account doesn't exist!"); } bank.get(originAccountNumber).transfer(bank.get(destinationAccountNumber), money); bank.get(originAccountNumber) .getHistory() .add( String.format( "Transfered %d to bank account with number %d", money, destinationAccountNumber)); bank.get(destinationAccountNumber) .getHistory() .add( String.format( "Received %d from bank account with number %d", money, originAccountNumber)); }
public static void main(String[] args) { try { Bank bulgarianBank = new Bank("BNB", "Sofia", 1000000); List<Client> clients = new ArrayList<Client>(); Random rand = new Random(); for (int i = 0; i < 20; i++) { Client c = new Client( "Client" + i, "Sofia", rand.nextInt(10000) + 420, rand.nextFloat() * rand.nextInt(100000) + 10); c.createDeposit((80 + rand.nextInt(20) + 1) * c.getMoney() / 100, 12, 3, bulgarianBank); if (rand.nextInt(2) + 1 == 1) c.askForCredit("HomeCredit", rand.nextInt(1000) + 100, 12, bulgarianBank); else { c.askForCredit("ConsumerCredit", rand.nextInt(1000) + 100, 12, bulgarianBank); } clients.add(c); } System.out.println("BNB-money: " + bulgarianBank.getMoney()); System.out.println("BNB-reserve: " + bulgarianBank.getReserve()); } catch (Exception e) { e.printStackTrace(); } }
/** Prompts user for info, then carry out the transfer operation in Bank. */ private static void transfer() { String prompt = "Please enter the account number to transfer FROM: "; int transferFromAccount = (int) getChoice(prompt); prompt = "Please enter the account number to transfer TO: "; int transferToAccount = (int) getChoice(prompt); prompt = "Please enter the amount to transfer: "; double amount = getChoice(prompt); ; try { theBank.transfer(transferFromAccount, transferToAccount, amount); System.out.println("\nTransfer successful."); System.out.printf( "Balance of account #: %d is %.2f\n", transferFromAccount, theBank.getBalanceForAccount(transferFromAccount)); System.out.printf( "Balance of account #: %d is %.2f\n\n", transferToAccount, theBank.getBalanceForAccount(transferToAccount)); } catch (AccountDoesNotExistException e) { System.out.println("\nOne of the accounts doesn't exist in this bank."); } catch (NegativeMoneyException e) { System.out.println("\nAmount to transfer has to be >= 0"); } catch (InsufficientFundsException e) { System.out.println("\nInsufficient funds in this account to transfer the given amount."); } catch (NotSameOwnerException e) { System.out.println("\nThese accounts don't belong to the same owner."); } }
@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); }
@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); }
public void payToPlayer(Player payee, Long amount) { // if calling giveMoney will be anything but not 0 then all belongings go to payee Long owed = this.giveMoney(amount); payee.getMoney(amount - owed); if (owed > 0) { StdOut.println(this.name + " owes to " + payee.name + " " + Bank.moneyEuro(owed)); if (this == Game.getCurrentPlayer()) { // the moment player gave up it will stop recursing if (this.playing) { // allows player to sell something and then calls itself, // so it won't leave till it's paid ot player gave up this.sellProperty(); this.payToPlayer(payee, owed); } } else { for (BoardTile tile : BoardSearch.all().filterByOwner(this).getTiles()) { tile.changeOwner(payee); } // give payee money you got from selling of upgrades StdOut.println( payee + " got " + Bank.moneyEuro(this.cash) + " from " + this.name + "'s upgrades."); this.giveMoney(this.cash); this.cash = 0L; } } }
@Override public void setBank(Bank b) { bankRef = b; if (bankRef != null) { bankName.setText(bankRef.getName()); bankCode.setText(bankRef.getCode()); } }
/** Returns all bank markets */ public List<Market> getBankMarkets() { List<Market> markets = new ArrayList<Market>(); for (Bank bank : bankByMarketMap.values()) { markets.add(bank.getMarketId()); } return markets; }
/** * Create an instance of {@link Bank } * * @param name * @param bills */ public Bank createBank(String name, Bill... bills) { Bank bank = new Bank(); bank.setName(name); for (Bill bill : bills) { bank.getBill().add(bill); } return bank; }
/** @param args */ public static void main(String[] args) throws Exception { System.out.println(System.getProperty("java.version")); Bank b = new KundenGenerator().fuelleBank(new Bank()); MainView mv = new MainView(b); b.addObserver(mv); // b.menuBank(); }
@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); }
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); }
// this players cash will increase by amount public void getMoney(Long amount) { this.cash += amount; StdOut.println( this.name + " got " + Bank.moneyEuro(amount) + " (current cash " + Bank.moneyEuro(this.cash) + ")"); }
@Before public void setUp() throws Exception { SEK = new Currency("SEK", 0.15); SweBank = new Bank("SweBank", SEK); SweBank.openAccount("Alice"); testAccount = new Account("Hans", SEK); testAccount.deposit(new Money(10000000, SEK)); SweBank.deposit("Alice", new Money(1000000, SEK)); }
@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); }
/** * This method does the actual trade by interacting with the bank and the Current Player to * ascertain the port type and what if they can trade or not. * * @pre the resource types it receives are valid, and that tradeIn is what the player performing * the trade already has * @throws Exception */ public void doMaritimeTrade(ResourceType tradeIn, ResourceType receive) throws Exception { if (canDoPlayerDoMaritimeTrade(tradeIn, receive)) { ResourceCard[] tradingCards = currentPlayer.prepareBankTrade(tradeIn); bank.playerTurnInResources(tradingCards); currentPlayer.getResourceCardHand().addCard(bank.playerTakeResource(receive)); } else throw new Exception("Cannot do Maritime Trade"); }
public void showHistory() throws NonExistingBankAccountException { Scanner scanner = new Scanner(System.in); System.out.println("Enter account number: "); long accountNumber = Long.parseLong(scanner.nextLine()); scanner.close(); if (bank.get(accountNumber) == null) { throw new NonExistingBankAccountException("Bank account doesn't exist!"); } bank.get(accountNumber).getHistory().showHistory(); }
private boolean execute(CashCorrectionAction cashAction) { boolean result = false; CashHolder ch = cashAction.getCashHolder(); int amount = cashAction.getAmount(); String errMsg = null; while (true) { if (amount == 0) { errMsg = LocalText.getText("CorrectCashZero"); break; } if ((amount + ch.getCash()) < 0) { errMsg = LocalText.getText( "NotEnoughMoney", ch.getName(), Bank.format(ch.getCash()), Bank.format(-amount)); break; } break; } if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CorrectCashError", ch.getName(), errMsg)); result = true; } else { // no error occured gameManager.getMoveStack().start(false); Bank bank = gameManager.getBank(); String msg; if (amount < 0) { // negative amounts: remove cash from cashholder new CashMove(ch, bank, -amount); msg = LocalText.getText("CorrectCashSubstractMoney", ch.getName(), Bank.format(-amount)); } else { // positive amounts: add cash to cashholder new CashMove(bank, ch, amount); msg = LocalText.getText("CorrectCashAddMoney", ch.getName(), Bank.format(amount)); } ReportBuffer.add(msg); gameManager.addToNextPlayerMessages(msg, true); result = true; } return result; }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); Bank bank = new Bank(); int index = 0; do { System.out.println("1.存款 2.取款 3.退出"); System.out.println("请选择你需要办理的业务"); int num = input.nextInt(); bank.menu(num); if (num != 0) { index = 1; } } while (index == 1); }
public void setBankSize(Player player, int size) { bank = banks.get(player.getName()); Inventory inv = bank.getInv(); ItemStack gt = inv.getItem(inv.getSize() - 2); ItemStack st = inv.getItem(inv.getSize() - 1); inv.remove(gt); inv.remove(st); bank.setBankSize(size); Inventory in = Bukkit.createInventory(player, size, player.getName() + " - Bank Chest"); in.setContents(inv.getContents()); bank.setInv(in); in.setItem(in.getSize() - 1, st); in.setItem(in.getSize() - 2, gt); sql.updateInv(player.getName(), size, in); }
public void withdrawMoney() throws InsufficientFundsException, Exception { Scanner scanner = new Scanner(System.in); System.out.println("Enter account number: "); long accountNumber = Long.parseLong(scanner.nextLine()); System.out.println("Enter amount of money you want to withdraw: "); double money = Double.parseDouble(scanner.nextLine()); scanner.close(); if (bank.get(accountNumber) == null) { throw new NonExistingBankAccountException("Bank account doesn't exist"); } bank.get(accountNumber).withdraw(money); bank.get(accountNumber).getHistory().add(String.format("Withdrawed %d", money)); }
private int displayPlayerMenu() { ArrayList<String> items = new ArrayList<String>( Arrays.asList( "Roll dice", "Show my properties", "Show players stats", "Sell to other player", "Downgrade properties", "Mortages", "Give up", "Suspend game (save & exit)", "Stop on request (just exit)")); if (debug) { items.add("Debug options"); } return UI.displayMenuNGetChoice( Game.getCurrentPlayer() + "'s options (" + Bank.moneyEuro(Game.getCurrentPlayer().getCash()) + " cash)", items, false, false); }
private int displayDebugMenu() { ArrayList<String> items = new ArrayList<String>( Arrays.asList( "Exit debugging", ((Game.getDebugDice()) ? "Disable" : "Enable") + " dice debugging", "Jump to tile #", "Execute current tile action", "Set your cash", "Set jail time", "Pick community card", "Pick chance card", "Show deck sizes", "Switch to other player", "Display board", "Access available upgrades")); StdOut.println( "\nWARNING !!! Be careful, you could break the game.\n Some of these functions do not do any sanity checks!!!"); StdOut.println( "And really if some of these functions is used in some situations, it will make the game misbehave."); return UI.displayMenuNGetChoice( "Debug options (" + Bank.moneyEuro(Game.getCurrentPlayer().getCash()) + " cash)", items, true, true); }
@Override public String getText() { if (stockPrice != null) { return Bank.format(stockPrice.getPrice()) + " (" + stockPrice.getName() + ")"; } return ""; }
/** * The art of placing a settlement on the vertex. * * @pre the Can do is true * @param vertexLocation * @throws Exception * @post a settlement is placed on a vertex */ public void placeSettlementOnVertex(int UserId, VertexLocation vertexLocation) throws Exception { if (canDoPlaceSettlementOnVertex(UserId, vertexLocation) == false) { throw new Exception( "Cannot build Settlement on this vertex, this should not have been allowed to get this far."); } // If we are in the first two rounds of the game if (turnNumber < 2) { board.placeInitialSettlementOnVertex(currentPlayer, vertexLocation); versionNumber++; // Here we collect the resources for the second placed settlement in setup round if (turnNumber == 1) { Hex[] adjacentHexes = board.getVertex(vertexLocation).getAdjacentHexes(); for (Hex hex : adjacentHexes) { if (hex != null) { ResourceType hexResourceType = hex.getHexResourceType(); ResourceCard card = bank.playerTakeResource(hexResourceType); currentPlayer.getResourceCardHand().addCard(card); } } } } else { board.placeSettlementOnVertex(currentPlayer, vertexLocation); versionNumber++; } }
@Override public void askForCredit(String typeOfCredit, double amount, int period, Bank myBank) throws NotEnoughMoneyException { if (creditStatus() && myBank.creditCheck(amount)) { Credit newCredit = Credit.makeNewCredit(typeOfCredit, period, amount); this.myCredits.add(newCredit); myBank.transferAccountToDataBase(newCredit); } }