📄 loantest.java
字号:
/**
* Created by IntelliJ IDEA.
* User: shaohj
* Date: 2005-8-30
* Time: 18:17:33
* To change this template use File | Settings | File Templates.
*/
import javax.swing.JOptionPane;
import java.text.*;
public class LoanTest {
public static void main(String[] args) {
//声明3个变量
double aloanAmount, monthlyPayment, totalPayment ;
//创建贷款计算器对象
Loan aLoan=new Loan();
//调用贷款计算器对象的setLoanAmount方法
// 将贷款计算机对象贷款数量的值设置为20000.0
aLoan.setLoanAmount(20000.0);
// 调用贷款计算器对象的setLoanPeriod方法
//将贷款周期属性的值设置为12(单位年)
aLoan.setYears(12);
//调用贷款计算器对象的setAnnualInterestRate方法
//将年利率属性的值设置为7(即7%)
aLoan.setAnnualInterestRate(7.0f);
//调用贷款计算器对象的computeMonthlyPayment方法计算月付款
// 并将方法的返回值付给变量 monthlyPayment
monthlyPayment=aLoan.computeMonthlyPayment();
//调用贷款计算器对象的computeTotalPayment方法计算总付款
// 并将方法的返回值付给变量totalPayment
totalPayment=aLoan.computeTotalPayment();
// 调用贷款计算器对象的getLoanAmount方法读取贷款数量属性的值
aloanAmount=aLoan.getLoanAmount();
//调NumberFormat类的getCurrencyInstance
// 创建 NumberFormat对象currencyformatter
//准备将指定数值的格式化为货币
NumberFormat currencyformatter=NumberFormat.getCurrencyInstance();
//连接字符串付给String类型的变量output
String output="贷款金额: "+currencyformatter.format(aloanAmount)+"\n"+
"贷款周期: "+aLoan.getMonths()+"(月)\n"+
"年利率: "+aLoan.getAnnualInterestRate()+"%"+"\n"+
"月付款: "+currencyformatter.format(monthlyPayment)+"\n"+
"总付款: "+ currencyformatter.format(totalPayment)+"\n\n";
aLoan.setMonths(24);
monthlyPayment = aLoan.computeMonthlyPayment();
totalPayment = aLoan.computeTotalPayment() ;
output+="贷款金额: "+currencyformatter.format(aloanAmount)+"\n"+
"贷款周期: "+aLoan.getYears()+"(年)\n"+
"年利率: "+aLoan.getAnnualInterestRate()+"%"+"\n"+
"月付款: "+currencyformatter.format(monthlyPayment)+"\n"+
"总付款: "+ currencyformatter.format(totalPayment)+"\n";
//在消息框中显示字符串output
JOptionPane.showMessageDialog( null,output,
"结果",+JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -