• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

loan amount calculation - java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.println("-------------------------------------------------------------");
System.out.println("|                    Calculate Loan amount                  |");
System.out.println("-------------------------------------------------------------");
System.out.print("Input Employee name   - ");
String name = input.next();
System.out.print("Input Employee salary - ");
int salary = input.nextInt();
if(salary>50000){
System.out.print("Enter number of year - ");
int numOfYear = input.nextInt();
double loan_amount = (salary*0.60)*1-(1/(1+Math.pow((15/12),(numOfYear*12)))/(15/12));

System.out.println("You can get Loan Amount : "+loan_amount);


If input salary =250000, no of years 3, loan amount should 4327000.

Where is the fault?
Screenshot_20230430_202050.jpg
[Thumbnail for Screenshot_20230430_202050.jpg]
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Bawantha,

welcome to the Ranch and enjoy the stay!

I see two mistakes in your code:

1) where you calculate the loan_amount, your parentheses are incorrect. Have a careful look at that line!

2) the monthly interest is not 15 / 12, but 0.15 / 12.

The formula given to you is quite unattractive. Here is a way to simplify the formulas a little:  link
 
Bawantha Madushan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Still outcome is not coming.
 
Piet Souris
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Allright.

Lets follow what I wrote in my link, cutting that complicated formula into simpler pieces.

If you want to have an amount of 1 at the bank, N periods from now, with an interest perunage of i per period, then you need to put now an amount of (1 + i) ^-N. This period can be a month, or a quarter, or a year, whatever, as long as that interest perunage i belongs to that period (an interest perunage is just the interest, not per 100 as we usually denote it, but per 1; so 15% becomes 0.15). We denote this value now as 'the present value' of that amount 1, and we denote is with A(N, i).

In your exercise, the period is a month, the number of periods is 3 * 12 = 36, and the interest perunage per month = 0.15 / 12.

Also, if you have a series of payments 1, at the times 1, 2, 3, 4, ..., N, then the present value of these payments at time 0 is:

1 * A(1, i) + 1 * A(2, i) + ... + 1 * A(N, i)

We denote this value as a(N, i)  (you see that in the actuarial world, case DOES matter, like in Java). Since we have that

A(n, i) * A(m, i) = A(n + m, i)

we can simplify this a(N, i) to

a(N, i) = ( 1 - A(N, i) ) / i

Now, if the payment is not 1 per period, but P, then what is the present value of these payments P?

Lets program what we have. First:




And finally:

the payment each month P = monthSalary * 0.6, if that is at least 50_000, the number of periods is 3 * 12 = 36, and the perunage per month = 0.15 / 12.

The present value of all these P's is P * a(36, 0.15 / 12), and so that is the loan that you can get.

Can you give it a try? And also, can you verify that my a(N, i) is exactly that complicated right-hand part of the formula that is given to you? Your teacher will probably ask for this  ;)

 
Always! Wait. Never. Shut up. Look at this tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic