java第六章习题2 模拟一个简单的购房商贷月供计算器

package com;

import java.util.Date;

public class  Mortgage{
public double money=0;
public double loan(double loan,int choose){
	switch(choose) {
	case 1:money = (loan + loan * 0.0603) / 36;
	       break;
	case 2:money = (loan + loan * 0.0612) / 60;
	       break;
	case 3:money = (loan + loan * 0.0639) / 240;
	       break;
	default:
		System.out.println("eorr!请重新输入!");
		break;
	}
	System.out.println("月供为:"+money);
	return money;
}
}
package com;

import java.util.Date;
import java.util.Scanner;

public class MortgageTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
           Mortgage mp=new Mortgage();
           Scanner sc=new Scanner(System.in);
           System.out.println("请输入贷款金额:");
           double money=sc.nextDouble();
           System.out.print("请选择贷款年限:1.3年(36个月)  2.5年(60个月)  3.20年(240个月):");
           int chiose=sc.nextInt();
           mp.loan(money, chiose);
            
          
	}

}

你可能感兴趣的:(java)