All pastes #908339 Raw Edit

Something

public text v1 · immutable
·published 2008-02-18 10:40 UTC
rendered paste body
public class Loan {
       public static void main(String[] args) {

        //Variable Declaration
        double interest, repayment, amount, time, lastAmount;
        int count, totalRests, rests, temp, yrtemp, monthtemp, rpy;
        long startTime, endTime;
        
        //User enters data
        TextIO.putln("Please enter values you are asked for.");
        TextIO.put("Starting value of loan? ");
        amount = TextIO.getDouble();
        TextIO.put("Interest Rate(%)");
        interest = TextIO.getDouble();
        TextIO.put("Repayment amount");
        repayment = TextIO.getDouble();
        TextIO.put("Rests per year");
        rpy= TextIO.getInt();
        count=0 ;
        lastAmount=0;
        //Calculations and output
        startTime=System.currentTimeMillis();
        TextIO.writeFile("results.txt");
        TextIO.putln("The loan details are as follows:");
        TextIO.putln("The Starting value is $" +amount+" The interest rate is " +interest+ "% The repayment per rest is $" +repayment+". There are " +rpy+ " rests per year.");
        while (amount > 0) {
            count+=1;
            amount+= (((interest/100.0)*(1.0/rpy)*amount) - repayment);
            TextIO.put("amount for rest " + count +" is $") ;
            TextIO.putf( "%1.2f" , amount);
            TextIO.putln(" ");
            if (amount<0) {
                break;
                }    
            }
        yrtemp= (int) count/rpy;
        monthtemp = (int) count%rpy;
        lastAmount = repayment + amount;
        TextIO.putln("The loan was paid off after " + yrtemp + " years and " + monthtemp + " rests.");
        TextIO.put("The last payment amount was $");
        TextIO.putf("%1.2f", lastAmount);
        TextIO.writeStandardOutput();
        TextIO.putln("Caclulations Complete, please refer to the text file generated.");
        endTime =System.currentTimeMillis();
        time = (endTime - startTime) / 1000.0;
        TextIO.putln("The time taken was " + time + " seconds");
        } // end of main()      
    } // end of class HomeLoan