1 Replies - 3828 Views - Last Post: 03 April 2013 - 07:00 PM Rate Topic: -----

#1 tkayp6546   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-April 13

Problem with Loan class and client LoanTest classes! (JAVA)

Posted 02 April 2013 - 02:23 PM

I am having trouble with a lab assignment. We are to create a user-defined Loan class and its client class, LoanTest. I also have a Date class already created .
Each loan object should store the following information:
a. Annual Interest Rate
b. Number of Years
c. Loan Amount
d. Loan Date (You would be specifying Loan Date of the type Date class you created earlier)

Here are the different operations that could be done on any Loan object...
Operation that returns the annual interest rate
Operation that returns the number of years
Operation that returns the loan amount
Operation that returns the Loan Date as a String value providing the date information.
Operation that sets a new annual interest rate
Operation that sets a new number of years
Operation that sets a new loan amount
Operation that calculates and returns the monthly payment
(Calculate the monthly payment using the following formulas:
Monthly payment = (mIR * M) / (1 (1 / (1 + mIR)(12*nOY) ))
mIR = monthly interest rate (annual interest rate / 12)
nOY = number of years
M = Loan amount
Operation that calculates the total payment amount over the life of the loan
Operation that returns the overpayment amount

For the client LoanTest class, I am instructed to:
Prompt the user for the annual interest rate.
Prompt the user for the number of years the loan will be held
Prompt the user for a number representing the loan amount borrowed from the bank.
Prompt the user for the start date of the loan.
Include necessary checks to validate the above input values.
Create the Loan object
Output a summary of the mortgage problem as follows:
The annual interest rate in percent notation
The mortgage amount in dollars
The monthly payment in dollars, with only two significant digits after the decimal point
The total payment over the years, with only two significant digits after the decimal point
The overpayment with only two significant digits after the decimal point
The overpayment as a percentage (in percent notation) of the mortgage amount

I keep trying to calculate and return the total payment, overpayment, and the percent of overpayment of the mortgage amount and they are wrong. I think it is a problem with my getOverpayment method in the Loan class and I cannot figure it out! Help! Here is my Loan class code:

public class Loan 


    private double rate; 
    private int years; 
    private double amount; 
    private Date loanDate;
    private double mPayment;

    public Loan(double r, int y, double a, Date d) 
        rate = r; 
        years = y; 
        amount = a; 
        loanDate = d; 

    public double getRate() 
        return rate; 

    public int getYears() 
        return years; 

    public double getAmount() 
        return amount; 

    public Date getLoanDate() 
        return loanDate; 

    public void setRate(double newRate) 
        rate = newRate; 

    public void setYears(int newYears) 
        years = newYears; 

    public void setAmount(double newAmount) 
        amount = newAmount; 
    public double getMPayment()
        double mRate = rate/12;
        double mPayment = (mRate*amount)/(1-(1/Math.pow((1+mRate),(12*years))));
        return mPayment;
    public double getOverpayment()
        double overpayment = ((mPayment*(12*years)) - amount);
        return overpayment;

Here is my LoanTest class code:

import java.util.Scanner; //Import the Scanner format class from the java.util package 
import java.text.NumberFormat;
public class LoanTest 


    public static void main(String [] args) 

        Scanner scan = new Scanner(System.in); //Instantiate a Scanner object to read from the InputStream System.in. 

        System.out.print("Please enter the loan rate: "); //Write a prompt for user to input the loan rate.  

        double rate = scan.nextDouble();  

        System.out.print("Please enter the number of years: "); //Write a prompt for user to input the number of years for the loan.
        int years = scan.nextInt();
        System.out.print("Please enter the loan amount: "); //Write a prompt for user to input the amount of the loan. 
        double amount = scan.nextDouble();
        System.out.print("Please enter the loan date: (MM DD YYYY)"); //Write a prompt for user to input the date. 
        int m = scan.nextInt(); 
        int d = scan.nextInt(); 
        int y = scan.nextInt(); 
        Date lDate = new Date (m,d,y); 
        Loan myLoan = new Loan(rate,years,amount,lDate); 
        NumberFormat percentFormat = NumberFormat.getPercentInstance();
        NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
        System.out.println("The annual interest rate is " +percentFormat.format(rate));
		System.out.println("The mortgage amount is: " +currencyFormat.format(amount));
		System.out.println("The monthly payment is: " +currencyFormat.format(myLoan.getMPayment()));
		System.out.println("The total payment over the " +years+ " year span is: " +currencyFormat.format(amount+(myLoan.getOverpayment())));
		System.out.println("The total amount of overpayment on the loan is: " +currencyFormat.format(myLoan.getOverpayment()));
		System.out.println("Therefore, the amount of overpayment is " +percentFormat.format((myLoan.getOverpayment())/amount)+" of the total mortgage amount");



Any suggestions to what I am doing wrong would be greatly appreciated! Also, this is more basic. We have not made it into any arrays or things like that yet so I will not understand any of those. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with Loan class and client LoanTest classes! (JAVA)

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Problem with Loan class and client LoanTest classes! (JAVA)

Posted 03 April 2013 - 07:00 PM

I suggest that you post your question using a normal font
these bold posting really hurt my 60 years old eyes and really discourage me to read the rest of the post
Actually it also let me think that the OP should spent more time learning Java rather than trying to learn how to make so called "fancy" posts.

This is a programmers site after all :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1