Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java please. I provided the code. public class Loan { private double annualInterestRate; private int numberOfYears; private double loanAmount; private java.util.Date loanDate; /** No-arg

In java please. I provided the code.

public class Loan { private double annualInterestRate; private int numberOfYears; private double loanAmount; private java.util.Date loanDate;

/** No-arg constructor */ public Loan() { this(2.5, 1, 1000); }

/** Construct a loan with specified annual interest rate, number of years, and loan amount */ public Loan(double annualInterestRate, int numberOfYears, double loanAmount) { this.annualInterestRate = annualInterestRate; this.numberOfYears = numberOfYears; this.loanAmount = loanAmount; loanDate = new java.util.Date(); }

/** Return annualInterestRate */ public double getAnnualInterestRate() { return annualInterestRate; }

/** Set a new annualInterestRate */ public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; }

/** Return numberOfYears */ public int getNumberOfYears() { return numberOfYears; }

/** Set a new numberOfYears */ public void setNumberOfYears(int numberOfYears) { this.numberOfYears = numberOfYears; }

/** Return loanAmount */ public double getLoanAmount() { return loanAmount; }

/** Set a newloanAmount */ public void setLoanAmount(double loanAmount) { this.loanAmount = loanAmount; }

/** Find monthly payment */ public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12))); return monthlyPayment; }

/** Find total payment */ public double getTotalPayment() { double totalPayment = getMonthlyPayment() * numberOfYears * 12; return totalPayment; }

/** Return loan date */ public java.util.Date getLoanDate() { return loanDate; } }

-------

import java.util.Scanner;

class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in);

// Enter yearly interest rate System.out.print( "Enter annual interest rate, for example, 8.25: "); double annualInterestRate = input.nextDouble();

// Enter number of years System.out.print("Enter number of years as an integer: "); int numberOfYears = input.nextInt();

// Enter loan amount System.out.print("Enter loan amount, for example, 120000.95: "); double loanAmount = input.nextDouble();

// Create Loan object Loan loan = new Loan(annualInterestRate, numberOfYears, loanAmount);

// Display loan date, monthly payment, and total payment System.out.printf("The loan was created on %s " + "The monthly payment is %.2f The total payment is %.2f ", loan.getLoanDate().toString(), loan.getMonthlyPayment(), loan.getTotalPayment());

} }

image text in transcribed

a. Modify the Loan class from Chapter 10 such that it will throw an IllegalArgumentException if the loan amount, interest rate or number of years is less than or equal to zero

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions