Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java program help!! (https://www.askmehelpdesk.com/showthread.php?t=770661)

  • Oct 9, 2013, 05:25 PM
    o21vais
    Java program help!!
    Dr.Java method and overloaded methods help in code?

    Write a program that uses two overloaded methods to calculate the monthly payment for a loan. The formula for calculating a payment is shown further down.

    Given that the user enters:
    - an annual interest rate such as 3.600%, which is the decimal value 0.036
    - the number of years over which the loan will be repaid such as 5.
    - a loan amount such as 10000 dollars

    Convert the annual values for the interest and years to monthly values:
    - the monthly interest rate, which we'll abbreviate as mir, is 0.036/12 or 0.003.
    - the number of months over which the loan will be repaid, which we'll abbreviate as mtp (months to pay), is 5 * 12 or 60.

    Annuity factor = mir/(1-(1/(1+mir))^mtp)

    In this example, the results of substituting the values in the formula are:

    Annuity factor = 0.003/(1-(1/(1+0.003))^60)
    Annuity factor = 0.018237

    Payment = Amount Loaned * Annuity Factor
    Payment = 10000*0.018237
    Payment = 182.37

    You must use the pow method in the Math class. This makes writing the annuity factor formula more awkward. It's easier if you break it down into some extra steps:

    1. Intermediate interest rate = Math.pow((1+0.003), 60)
    2. Annuity factor = 0.003 / (1-(1/Intermediate interest rate))

    Here's where the overloading comes in: some applications will define the amount as an int(integer), and other will define it as a double. Therefore, you need to write two overloaded versions of this method:

    1) one that takes the annual interest rate as a double, the number of years as an int and the amount loaned as an int(integer).

    2) another one that takes the annual interest rate as an double, the number of years as an int(integer) and the amount loaned as a double.

    Your main method will obtain input from the user who will provide an annual interest rate and the number of years over which the loan will be repaid. The payment calculating method will convert them to monthly values.

    Get user input only once and use cast operators to either convert int(integer ) value to double or double values to int(integer) before invoking a method.

    Use the data given in the example above to validate that methods correctly calculate loan payments.

    Use JOptionPane to obtain input from the user.

    ****** Please help me with this code this is my second time am using java program and I don't have much experience in this. Thanks.
    Additional Details
    I having hard time to begin with this program. HOw should I start and how can I use overloaded method.
  • Oct 9, 2013, 06:21 PM
    ma0641
    Surely you don't expect us to do this for you. Your instructor should help you. If you don't learn, what happens the third time?

  • All times are GMT -7. The time now is 07:32 AM.