package com.JUL10; import java.util.Scanner; // 计算每月还款金额 public class JiSuan { double zJE = 0; // 总金额 int age = 0; // 贷款多少年 boolean boo = true; // 判断输入年限的有效值 public JiSuan() { } public JiSuan(int age, double jE) { if (age > 0 && age <= 20 && jE >= 10000) { boo = true; this.age = age; if (age <= 3) { double liXi = 0.0603 * age; this.zJE = jE * (1 + liXi); } else if (age <= 5) { double liXi = 0.0612 * age; this.zJE = jE * (1 + liXi); } else if (age <= 20) { double liXi = 0.0639 * age; this.zJE = jE * (1 + liXi); } } else { boo = false; } } public void jiSuan() { double myhk = this.zJE / (this.age * 12); System.out.println("********月供为:" + myhk); } static Scanner input = new Scanner(System.in); public static void main(String[] args) { do { System.out.println("请输入贷款金额(最少不低于10000):"); double money = input.nextDouble(); System.out.println("请输入贷款年份(1~20):"); int age = input.nextInt(); JiSuan j1 = new JiSuan(age, money); if (j1.boo) { System.out.println("还款总金额:" + j1.zJE); j1.jiSuan(); } else { System.out.println("输入的贷款年限或贷款金额有误!"); } System.out.println("………………………………………………………………………………………………………………"); } while (true); } }
仅模拟计算贷款还款金额,懒得去判断你是否要继续操作