/** * @author KR * TaxPayment.java * Project Assignment #8 */ public class TaxPayment { //Each instance of this class will correspond to an individual tax payment //Define variable to store account owner's name private String taxPayer; //Define variable to store income private double inc; //Define constant for tax rate private static final double TAX_RATE=0.15; //Define variable to store tax due private double taxDue = 0.0; /******************* Constructor Methods *********************/ //Construct a TaxPayment object public TaxPayment ( String inputName, double inputIncome ){ //Initialize taxpayer with name provided taxPayer = inputName; inc = inputIncome; } /******************* Accessor Methods *********************/ //Accessor method to retrieve taxpayer name public String getTaxpayer () { return taxPayer; } //Accessor method to retrieve income public double getIncome () { return inc; } //Accessor method to retrieve tax owed public double getTax () { return taxDue; } /******************* Mutator Methods *********************/ //Mutator method to compute and set tax due based on income public void setTaxDue () { taxDue = TAX_RATE * inc; } //Mutator method to pay taxes and change account balances. //First determine if sufficient funds are in checking account to pay taxes. //If not enough funds, transfer money from savings to checking to cover the //amount lacking. public void payTax ( CheckingAccount checking1, SavingsAccount savings1 ){ boolean sufficientFunds = true; //Determine if enough money in checking account to cover tax due sufficientFunds = checking1.enoughFunds (taxDue ); //If enough money in checking account, withdraw tax due from it if ( sufficientFunds ) { checking1.withdraw ( taxDue ); } //If not enough money in checking account, transfer funds from savings account else { double transferAmount = taxDue - checking1.getBalance() + 100.0; savings1.withdraw (transferAmount ); checking1.deposit ( transferAmount ); checking1.withdraw ( taxDue ); } } /******************* Facilitator ("Helper" Methods *********************/ /******************* toString Methods *********************/ //Returns a useful String representation of the TaxPayment object public String toString() { return "A check for the amount of: $" + taxDue + " has been sent to the IRS " + "to pay the taxes of " + taxPayer + "."; } }