/** * @author KR * TaxApp.java * Project Assignment #8 */ import java.io.*; public class TaxApp { public static void main (String[] args) throws IOException { //Instantiate file object to read from file BufferedReader inFile = new BufferedReader(new FileReader("c:\\checks.txt")); //Instantiate input object to read from keyboard BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); //Variable to store user's name String name = ""; //Variable to store account initial checking account balance provided by user double startBalance = 0.0; //Variable to store income provided by user double income = 0.0; //Variable to store savings interest rate provided by user double interest = 0.0; //Variable to store one line from input data file String line = ""; //Variables to store data items taken from input data file double checkAmount; // PROMPT USER FOR INFORMATION REQUIRED //Prompt user for name System.out.println ( "Please enter your name:"); name = input.readLine (); //Prompt user for annual income System.out.println ( "Please enter your total annual income " + "( <= $ 50,000.0 )"); income = Double.parseDouble(input.readLine()); //Prompt user for starting balance for checking account. System.out.println ( "Please enter the starting balance of your " + "checking account (enter at least $100)."); startBalance = Double.parseDouble(input.readLine()); //Prompt user for interest rate for savings account. System.out.println ( "Please enter the interest rate of your " + "savings account"); interest = Double.parseDouble(input.readLine()); //Now we are ready to work with the accounts and make a tax payment. //We could have created a separate User object-creating class and had //the User call the various methods to perform these tasks, but we want //to avoid check file input operations in an object-creating class and //have not studied how to pass multiple related items (all the checks) //as a single argument yet. So we will simulate the User's actions //in this application class. // INSTANTIATE OBJECTS //Create new CheckingAccount object CheckingAccount c1 = new CheckingAccount ( startBalance ); //Create new SavingsAccount object with balance of $10,000.00 SavingsAccount s1 = new SavingsAccount ( 10000.0, interest ); // ADJUST BALANCES OF ACCOUNTS. ADD INTEREST TO SAVINGS. DEDUCT CHECKS FROM // CHECKING ACCOUNT. DEDUCT FEES (IF ANY) FROM CHECKING ACCOUNT. //Add interest to Savings Account s1.addInterest (); //Use while loop to process entire file of check amounts. line = inFile.readLine(); while ( line != null ) { //Deduct each check from checking account checkAmount = Double.parseDouble(line); c1.withdraw(checkAmount); line = inFile.readLine(); } //Close input file inFile.close(); //Deduct fees if transactions > FREE_TRANSACTIONS c1.deductFees (); //COMPUTE AND PAY TAXES TaxPayment payment1 = new TaxPayment ( name, income ); payment1.setTaxDue (); payment1.payTax ( c1, s1 ); System.out.println ( payment1.toString () ); //VERIFY ADJUSTED ACCOUNT BALANCES AFTER TAX PAYMENT //Print out values for Account objects System.out.println( "The checking account " + c1.toString () ); System.out.println( "The savings account " + s1.toString () ); } //End of main method } //End of TaxApp