private void createNewLoanRequest(ILoaner loaner, ICity city) { LocalDateTime now = date.getCurrentDate(); int duration = rnd.nextInt(50) + 10; int rankIndexBound = ESocialRank.values().length - 2; // no mayor or alderman final int rankIndex = rnd.nextInt(rankIndexBound); ESocialRank rank = ESocialRank.values()[rankIndex]; Citizen citizen = new Citizen(lastNameLoader.getRandomName(), maleFirstNameLoader.getRandomName(), rank, city); int amount = (rnd.nextInt(10000) + 1000) * (rankIndex + 1); LoanRequest request = LoanRequest.builder() .citizen(citizen) .durationInWeeks(duration) .issued(now) .sum(amount) .build(); loaner.add(request); }
/** * Take out a loan. * @param loaner from which to take the loan * @param proposal selected loan * @param debitor who is taking the loan. */ public void takeOutLoan(ILoaner loaner, ILoanProposal proposal, IPlayer debitor, ICity city) { // TODO: andi 6/12/16 the proposol might be on that is offed by a player and not a citizen LocalDateTime now = date.getCurrentDate(); ESocialRank rank = ESocialRank.values()[rnd.nextInt(ESocialRank.values().length-2)]; // Exclude Mayor and Alderman ICreditor creditor = new Citizen(lastNameLoader.getRandomName(), firstNameLoader.getRandomName(), rank, city); LocalDateTime dueDate = now.plusWeeks(proposal.getDurationInWeeks()); Debt debt = Debt.builder() .creditor(creditor) .amount(proposal.getAmount()) .dueDate(dueDate) .interest(proposal.getInterest()) .debitor(debitor) .loanTakeOut(now) .build(); loaner.addDebt(debt); loaner.getLoanProposals().remove(proposal); if (debitor instanceof IHumanPlayer) { debitor.getCompany().updateCash(proposal.getAmount()); } else { debitor.getCompany().updateCashDirectly(proposal.getAmount()); } }