From cefe245817447616e4f9910376968e293cd5bc58 Mon Sep 17 00:00:00 2001 From: Joe Hill Date: Thu, 30 Mar 2017 14:52:19 -0400 Subject: [PATCH] Make sure to check what financial statement covers before you guys work on the player class --- src/model/DealTile.java | 13 +-- src/model/FinancialStatement.java | 186 ++++++++++++++++++++++-------- src/model/OwnedRealEstate.java | 13 ++- src/model/Player.java | 2 +- 4 files changed, 152 insertions(+), 62 deletions(-) diff --git a/src/model/DealTile.java b/src/model/DealTile.java index d02d25d..bb3ce60 100644 --- a/src/model/DealTile.java +++ b/src/model/DealTile.java @@ -20,7 +20,7 @@ public void getLandedOn() // Ask user to decide big/small deal: // Pick card from big/small deal stack: // If stock, update price, then ask user if they want to buy and ask everyone if they want to sell: - // If property, ask user if they want to do it: + // If property, ask user if they want to do it (and check if they can afford the down payment): // If yes, call ButIncomeProperty method: // Else, do nothing: } @@ -28,15 +28,8 @@ public void getLandedOn() public void buyIncomeProperty(Player p, DealCard d) { FinancialStatement f = p.getFinancialStatement(); - - OwnedRealEstate newProperty = new OwnedRealEstate(d.getTitle(), d.getCost(), d.getDownPayment()); - f.addProperty(newProperty); - - // Add functionality in this ^^ to do this: - - //f.increaseCashBalance(-d.getDownPayment()); // Watch out for negatives - //f.increasePassiveIncome(d.getCashFlowChange()); - + OwnedRealEstate newProperty = new OwnedRealEstate(d.getTitle(), d.getCost(), d.getDownPayment(), d.getCashFlowChange()); + f.buyProperty(newProperty); } diff --git a/src/model/FinancialStatement.java b/src/model/FinancialStatement.java index f1187f4..0d800dd 100644 --- a/src/model/FinancialStatement.java +++ b/src/model/FinancialStatement.java @@ -2,49 +2,142 @@ import java.util.ArrayList; - public class FinancialStatement { + private Profession _profession; + private int _cashBalance; - private double salary; - private double interest; - private double[] realEstate; - private String career; - private double expenses; - public static double assets; //sorry i had to make this change to use w/ cards if i messed something up just change it im sorry!! - private double liabilities; - private double income; + + // Income + private int _income; // needs getter and incrementer + private int _salary; + private int _REcashFlow; // needs getter and incrementer + + // Expenses + private int _expenses; // needs getter and incrementer + private int _taxes; + private int _homeMortgagePayment; + private int _schoolLoanPayment; + private int _carLoanPayment; + private int _creditCardPayment; + private int _otherExpenses; + private int _perChildExpense; + private int _numChildren; // needs getter and incrementer + + // Assets + private int _assets; + private int _savings; private Stock _stock; - private ArrayList _realEstate = new ArrayList(); + private ArrayList _realEstate; + + // Liabilities + private int _liabilities; + private int _homeMortgage; + private int _schoolLoans; + private int _carLoans; + private int _creditCardDebt; + + // Cash flows (top right of actual financial statement) + private int _monthlySalary; + private int _passiveIncome; + private int _totalIncome; + private int _totalExpenses; + private int _monthlyCashFlow; + private boolean _hasWon; + + public FinancialStatement(Profession p) { - // TODO Set each major line item to the sum of the smaller ones - salary = p.getSalary(); + _profession = p; + + // Income + _income = 0; + _salary = p.getSalary(); + _REcashFlow = 0; + + // Expenses + _expenses = 0; + _taxes = p.getTaxes(); + _homeMortgagePayment = p.getMortgagePay(); + _schoolLoanPayment = p.getSchoolLoanPay(); + _carLoanPayment = p.getCarLoanPay(); + _creditCardPayment = p.getCreditCardPay(); + _otherExpenses = p.getOtherExp(); + _perChildExpense = p.getChildExpPer(); + _numChildren = 0; + + // Assets + _assets = 0; + _savings = p.getSavings(); + _realEstate = new ArrayList(); + + // Liabilities + _liabilities = 0; + _homeMortgage = p.getMortgage(); + _schoolLoans = p.getSchoolLoans(); + _carLoans = p.getCarLoans(); + _creditCardDebt = p.getCreditCardDebt(); + + // Cash flows + _monthlySalary = _salary; + _passiveIncome = 0; + _totalIncome = 0; + _totalExpenses = 0; + _monthlyCashFlow = 0; + _hasWon = false; + update(); } - public void setChildExp(int i) // One of these for each of the little line items that actually change + private void update() { - //childExp = i; - update(); + _income = _salary + _REcashFlow; + _expenses = _taxes + _homeMortgagePayment + _schoolLoanPayment + _carLoanPayment + _creditCardPayment + _otherExpenses + (_perChildExpense * _numChildren); + _assets = getOwnedREValue() + _savings; + _liabilities = _homeMortgage + _schoolLoans + _carLoans + _creditCardDebt; + + _passiveIncome = getPassiveIncome(); + _totalIncome = _monthlySalary + _passiveIncome; + _totalExpenses = _expenses; + _monthlyCashFlow = _totalIncome - _totalExpenses; + _hasWon = _passiveIncome > _totalExpenses; } + private int getPassiveIncome() + { + int passiveInc = 0; + for(OwnedRealEstate re : _realEstate) + { + passiveInc += re.getCashFlow(); + } + return passiveInc; + } + + public int getOwnedREValue() + { + int reValue = 0; + for(OwnedRealEstate re : _realEstate) + { + reValue += re.getPrice(); + } + return reValue; + } - private void update() + public void buyProperty(OwnedRealEstate newProperty) { - //expenses = asdf +asdf_A+sdf+ASDf - //income = blah+ blah - //cashflow = bluh + bluh - + _cashBalance -= newProperty.getDownPayment(); + _realEstate.add(newProperty); + update(); } - + public void buyStock(int numShares, int sharePrice) { _stock = new Stock(numShares, sharePrice); int cashOut = _stock.getCashOut(); _cashBalance += cashOut; // getCashOut() will negate the value automatically so we will add not subtract + update(); } public void sellStock() @@ -53,45 +146,38 @@ public void sellStock() _stock = null; } - Profession p = new Profession("Teacher", 3300, 500, 500, 100, 100, 200, 700, 0, 0, - 200, 400, 50000, 12000, 5000, 4000); - - public double expenses() + public void addChild() { - expenses = p.getTaxes() + p.getMortgagePay() + p.getSchoolLoanPay() + p.getCarLoanPay() - + p.getCreditCardPay() + p.getOtherExp() + p.getBankLoanPay() + p.getChildExp(); - return expenses; + // People can only have 3 children + if(_numChildren < 3) + { + _numChildren++; + } + update(); } - public double assets() - { - assets = p.getSavings(); - - return assets; - } - public double liabilities() - { - liabilities = p.getMortgage() + p.getSchoolLoans() + p.getCarLoans() + p.getCreditCardDebt(); - return liabilities; - } - public double income() + public int getCashBalance() { - income = p.getSalary(); - return income; + return _cashBalance; } - public void display() + public void increaseCashBalance(int cashIncrease) { - + this._cashBalance =+ cashIncrease; } - public int getCashBalance() { - return _cashBalance; - } - public void increaseCashBalance(int cashIncrease) { - this._cashBalance =+ cashIncrease; - } } + + + + + + + + + + + diff --git a/src/model/OwnedRealEstate.java b/src/model/OwnedRealEstate.java index 7c2c321..f12842c 100644 --- a/src/model/OwnedRealEstate.java +++ b/src/model/OwnedRealEstate.java @@ -5,12 +5,14 @@ public class OwnedRealEstate private String _name; private int _price; private int _downPayment; + private int _cashFlow; - public OwnedRealEstate(String name, int price, int downPayment) + public OwnedRealEstate(String name, int price, int downPayment, int cashFlow) { _name = name; _price = price; _downPayment = downPayment; + set_cashFlow(cashFlow); } public String getName() { @@ -21,10 +23,19 @@ public int getPrice() { return _price; } + /** + * + * @return Returns a positive value for down payment!! + */ public int getDownPayment() { return _downPayment; } + public int getCashFlow() { + return _cashFlow; + } + + diff --git a/src/model/Player.java b/src/model/Player.java index 3f17889..1686bc0 100644 --- a/src/model/Player.java +++ b/src/model/Player.java @@ -25,7 +25,7 @@ public FinancialStatement getFinancialStatement() return _fs; } - public boolean donateCharity() { + public boolean donateCharity() { // return false; }