-->
当前位置:首页 > 题库

PROGRAMMING:Design a loan class that can handle exceptions

Luz5年前 (2021-05-10)题库370
Define a loan class, in which there are attributes:
annualInterestR ate:double , indicating the annual interest rate of the loan (default: 2.5)
numberOfY ears:int , indicating the number of years of the loan (default: 1)
loanA mount:double , indicating the loan amount (default: 100)
loanD ate:java.util.Date , indicating the date the loan was created
Definition method:
(1) Default nonparametric construction method
(2) Construction method with specified interest rate, years and loan amount
(3) Get / set method for all properties
(4) Return the monthly payment of this loan getmonthlypayment ()
Monthly payment = (loan line * monthly interest rate) / (1 - (1 / math. Pow (1 + monthly interest rate, years * 12)))
(5) Return the total payment of this loan gettotalpayment ()
Total payment amount = monthly payment amount * years * 12
Attach the following test classes.
```
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
double AIR = input.nextDouble();
int NOY = input.nextInt();
double LA = input.nextDouble();
try {
Loan m = new Loan(AIR, NOY, LA);
System.out.printf("%.3f\n",m.getTotalPayment());
} catch (Exception ex) {
System.out.println(ex);
}
}
}
}
```
###Input format:
There are multiple sets of data input, one real number represents the annual interest rate, one integer represents the number of years, and one real number represents the total loan amount.
###Output format:
If any item is less than or equal to zero, the illegalargumentexception exception and the corresponding description (number of years must be positive or annual interest rate must be positive or loan amount must be positive) are thrown; In case of multiple non conformities, the first one shall prevail;
If all meet the requirements, output the total amount according to the format.
###Input example:
Here is a set of inputs. For example:
```in
1 1 1000
2.0 0 2000
0 0 0
```
###Output example:
The corresponding output is given here. For example:
```out
one thousand and five point four two five
java.lang.IllegalArgumentException: Number of years must be positive
java.lang.IllegalArgumentException: Annual interest rate must be positive
```







answer:If there is no answer, please comment