Hello, iam a student who is currently studying for an FD in IT,
I need a bit of help with my java assignment and as it is a mortgage calculator i am developing, maths is not my strongest subject
I have been trying to find out how to take in a value via my GUI of £1000, and print the answer to this sum out to a label:

LA = Loan Amount
If LA <= 1000
Then add interest rate of 0.97
Else

Add interest rate of 0.77

Store answer in Variable

ALL HELP WILL BE MUCH WELCOME
Thanks steve

what exactly do you want help with? do you want us to check your code for errors, than please post your code.

I'm pretty sure you understand the concept of intrest and percentage, so you should be able to work out the logic on yourself.

here is what i have in my Loan.java class

public void setLoanAmount (double la)
    
    {
        LA=la;
    
    
    
       if (LA <=1000 )
    
    {
intrest =   0.097 ;
    }

else
    {
intrest = 0.077 ;
    }
intrest = Math.abs(intrest *1000+.5)/1000;
 intrest2 = LA * 100 / intrest;
}


  public double getLoanAmount ()
{
   return intrest2;
 
}

if i enter a value of £1000 the result i get is 1025641.
if i enter a value of £10001 the result i get is 12904516.

if i am right! when i enter a value of £1000, i should get a result of £10987,

i carnt understand what i am doiing wrong!!

you're adding a lot of logic in your setters, and you're using a lot of class variables, where as you should better use local variables, to avoid confusion.

I'll take a look into your logic in a minute.

edit: quick question:

Then add interest rate of 0.97 -> is this 97% or 0.97%
in the first part, it would be double b = 0.97, in the second it would be 0.097, or do I get this wrong?

Edited 5 Years Ago by stultuske: n/a

My assignment asks me to add 0.97% interest to the customers loan, however if the customer requires a loan that exceeds £10000 then 2% is deducted from the interest rate which means:

on any loan that is greater than £10000 then a interest rate of 0.77% is added to the loan.

Your uncommented code makes it hard to understand what you intend the code to do.
For example what is the 1000 that is used two times in this statement:

intrest = Math.abs(intrest *1000+.5)/1000;

For better readability use a final int with a selfdocumenting name:

final int ConvertFactor = 1000;

Also I'm confused by your definition of %
1% of 1000 is 10
.9% of 1000 is 9
.97% of 1000 is 9.7

Edited 5 Years Ago by NormR1: n/a

sorry about that, i have commented the code below

public void setLoanAmount (double la)
    
    {
///The amount of loan the user requires is stored in ( la )////

        LA=la;
    
    
    
       if (LA <=1000 )
    
    {

//////If loan amount is less than or equal to 10000 than add 0.97% interest ///////
intrest =   0.097 ;
    }

else
    {
////////if loan is grater than 10000 than add 0.77% interest
intrest = 0.077 ;
    }
intrest = Math.abs(intrest *1000+.5)/1000;
}


  public double getLoanAmount ()
{

////Store loan amount with the interest added to it in variable (intrest) //////
   return intrest;
 
}

I have taken the last bit of code away (intrest2 = LA * 100 / intrest;) for i didn’t mean for that to be there sorry.

To be very honest, my tutor gave me this bit of code (intrest = Math.abs(intrest *1000+.5)/1000;). I honestly don’t know what its for, he never explained to us how the code works, we have a bad tutor.

intrest = Math.abs(intrest *1000+.5)/1000;

print out the results and see what it does. It looks like it rounds up.

This was added on my last post and you probably missed it:

Also I'm confused by your definition of %
1% of 1000 is 10
.9% of 1000 is 9
.97% of 1000 is 9.7

intrest = 0.097 ; // This is for 9.7%

Edited 5 Years Ago by NormR1: n/a

below is an extract of what i am required to do to acomplish this assignmment

Outline of the problem

As an employee of a software company, you have been asked to develop a small part of a software system for a company that offers mortgages and other loans. Your job as a programmer in the software development team is to create a function that can calculate the monthly payment on a home mortgage or other loan, give the amount of the loan, the interest rate, the payment period, and whether the interest is simple or compound.

List of Tasks

Task 1

. The system should accept the following information as an input:
• name of the customer
• address
• date of birth
• occupation
• the amount of the loan
• how long is the loan for

The base interest rate is 9.7%, however:
• if the loan exceeds £10,000, than subtract 2.0% from the interest rate

Task 2

The System should print out the following information as an output:
• Name of the Customer
• Address
• Date of birth
• The amount of the loan
• The monthly payment on the loan
• How long is the loan for in months

hope this makes it a bit clear, sorry if i am confusing you

I'm not sure that I was the only one confused.
Where are you now with the expression to compute the total = principal + interest?

This article has been dead for over six months. Start a new discussion instead.