public class LoanPayments {
// place constant declarations (static final) below.
// e.g. 3% interest, 9% repayment, 5% pay rise and 10k theshold
static final double INTEREST = 0.03, REPAID = 0.09, PAYRISE = 0.05, NET = 10000;
public static void main(String args[]) {
double loans, prevloan, newloan, wages, net, interest, newlinterest=0, linterest=0, wagest=0, newwages=0, repaid=0, balance=0, newbalance=0, yrbal=0, year=1;
// place all variable declarations here
System.out.println(" Student Loan" );
loans = UserInput.readDouble();
// prompt and read the loan amount
System.out.println (" Wages ");
wages = UserInput.readDouble();
interest = loans * INTEREST;
// add 3% to the loan
net = wages - NET;
// deduct 10k from the wages
repaid = net * REPAID;
// from the remaining wages calculate 9% repayment
linterest = loans + interest;
balance = linterest - repaid;
// reapaid loan amount
wagest = net;
yrbal= balance * year;
// sum up repayments and years so far
System.out.println(" Year " + (int)year);
MoneyOut.println(" Old Loan ", (int)loans);
// produce output: current year, old loan,
MoneyOut.println(" Loans plus 3% interest ", linterest);
// loan plus 3% interest, wages,
MoneyOut.println(" Wages ", (int)wages);
MoneyOut.println(" Wages minus threshold ", wagest);
//wages minus 10,000 pounds, repayment, new loan
MoneyOut.println(" Repayment ", (int)repaid);
MoneyOut.println(" New loan amount ", balance);
while (newbalance>0) {
// while loop starts here
year++;
prevloan = balance;
newloan = prevloan;
interest = newloan * INTEREST;
// add 3% to the loan
newwages = wages + (wages * 5.0 /100.0);
// calculate new wages by adding a pay rise of 5%
net = newwages - NET;
// deduct 10k from the wages
repaid = net * REPAID;
// from the remaining wages calculate 9% repayment
//if (newwages <0) {
// repaid =0;
//}
// (if the remaining wages are zero or less, repayment is zero)
newlinterest = newloan + interest;
newbalance = newlinterest - repaid;
// reapaid loan amount
wagest = net;
yrbal= newbalance * year;
// sum up repayments and years so far
System.out.println(" Year " + (int)year);
MoneyOut.println(" Old Loan ", (int)balance);
// produce output: current year, old loan,
MoneyOut.println(" Loans plus 3% interest ", newlinterest);
// loan plus 3% interest, wages,
MoneyOut.println(" Wages ", (int)newwages);
MoneyOut.println(" Wages minus threshold ", wagest);
//wages minus 10,000 pounds, repayment, new loan
MoneyOut.println(" Repayment ", (int)repaid);
MoneyOut.println(" New loan amount ", newbalance);
if (year >=30)
{
System.out.println(0);
} // 'break' out of the 'while' loop if more than 30 years have passed
} // end of the 'while' loop, program leaves it when loan is 0 or less
System.out.println(" It took you " +(int)year +
" years to repay the loan ");
// print out the number of year it took to repay the loan
System.out.println(" The orginal loan was " + "£" + loans +
" but you had to pay back " + yrbal);
// print out the original loan and the total amount paid back
// When 'debugging' you can use the code below to allow
// the loop to run one year at a time. Take it out when
// submitting to CourseMarker !!!
// System.out.println("Press 'Enter' to continue");
// UserInput.readString(); // waits for 'Enter'
} // end of main
} // end of class LoanPayments