java - I don't understand how to display my calculations -
this program lets user enter loan amount , loan period in number of years.
the monthly , total payments should displayed interest rate increments 1/8. far, have gotten far enough calculate 1 amount correctly don't understand how display results.
i took picture of instructions problem below:
import java.util.scanner; class computeloan { public static void main(string[] args) { scanner input = new scanner(system.in); //enter number of years system.out.print("enter number of years integer: "); int numberofyears = input.nextint(); //enter loan amount system.out.print("enter loan amount: "); double loanamount = input.nextdouble(); //declare interest rate double interestrate = 5.000; //obtain monthly interest rate double monthlyinterestrate = interestrate / 1200; //calculate payment double monthlypayment = loanamount * monthlyinterestrate / (1 - 1 / math.pow(1 + monthlyinterestrate, numberofyears * 12)); double totalpayment = monthlypayment * numberofyears * 12; (double intrate=5.000; intrate <8.000; intrate = intrate + .125); { double intrate=5.000; system.out.println("the interestrate " + intrate); system.out.println("the monthly payment $" + (int)(monthlypayment * 100) / 100.0); system.out.println("the total payment $" + (int)(totalpayment * 100) / 100.0); } //display results } }
hello try calculating in loop this
import java.util.scanner; class computeloan { public static void main(string[] args) { scanner input = new scanner(system.in); //enter number of years system.out.print("enter number of years integer: "); int numberofyears = input.nextint(); //enter loan amount system.out.print("enter loan amount: "); double loanamount = input.nextdouble(); (double intrate=5.000; intrate <8.000; intrate = intrate + .125) { //obtain monthly interest rate double monthlyinterestrate = intrate / 1200; //calculate payment double monthlypayment = loanamount * monthlyinterestrate / (1 - 1 / math.pow(1 + monthlyinterestrate, numberofyears * 12)); double totalpayment = monthlypayment * numberofyears * 12; system.out.println("the interestrate " + intrate); system.out.println("the monthly payment $" + (int)(monthlypayment * 100) / 100.0); system.out.println("the total payment $" + (int)(totalpayment * 100) / 100.0); } } }
the output
enter number of years integer: 5 enter loan amount: 10000 interestrate 5.0 monthly payment $188.71 total payment $11322.74 interestrate 5.125 monthly payment $189.28 total payment $11357.13 interestrate 5.25 monthly payment $189.85 total payment $11391.59 interestrate 5.375 monthly payment $190.43 total payment $11426.11 interestrate 5.5 monthly payment $191.01 total payment $11460.69 interestrate 5.625 monthly payment $191.58 total payment $11495.34 interestrate 5.75 monthly payment $192.16 total payment $11530.06 interestrate 5.875 monthly payment $192.74 total payment $11564.83 interestrate 6.0 monthly payment $193.32 total payment $11599.68 interestrate 6.125 monthly payment $193.9 total payment $11634.58 interestrate 6.25 monthly payment $194.49 total payment $11669.55 interestrate 6.375 monthly payment $195.07 total payment $11704.59 interestrate 6.5 monthly payment $195.66 total payment $11739.68 interestrate 6.625 monthly payment $196.24 total payment $11774.85 interestrate 6.75 monthly payment $196.83 total payment $11810.07 interestrate 6.875 monthly payment $197.42 total payment $11845.36 interestrate 7.0 monthly payment $198.01 total payment $11880.71 interestrate 7.125 monthly payment $198.6 total payment $11916.13 interestrate 7.25 monthly payment $199.19 total payment $11951.61 interestrate 7.375 monthly payment $199.78 total payment $11987.16 interestrate 7.5 monthly payment $200.37 total payment $12022.76 interestrate 7.625 monthly payment $200.97 total payment $12058.44 interestrate 7.75 monthly payment $201.56 total payment $12094.17 interestrate 7.875 monthly payment $202.16 total payment $12129.97