日期:2014-05-20  浏览次数:20627 次

求指教 java实验哦
实验3:根据用户存款天数计算银行利息
实验要求:
计算某年、某月、某日和某年、某月、某日之间的天数间隔。并根据天数计算利息的程序。假设年息为2.4%。要求通过键盘输入存款的年、月、日和取款的年、月、日。

------解决方案--------------------
public class ChangeNum {
public static void main(String [] args){
long d=new CalculateDay().calculate();
System.out.println(" 输入你的存款:");
Scanner scan=new Scanner(System.in);
double amount=scan.nextDouble();
System.out.println("存款为:"+new Bank().calculateProfit(d,amount));
 
}

}
class Bank{
private final double interestRate=0.024;
public double calculateProfit(long d,double m){
return (d/(double)(365))*interestRate*m;
}
}
class CalculateDay{
public long calculate(){
Calendar cal=Calendar.getInstance();
System.out.println("请输入您的存款年份:");
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
System.out.println("请输入您的存款月份:");
int b=scan.nextInt();
System.out.println("请输入您的存款日期:");
int c=scan.nextInt();
cal.set(a, b, c);
long day_1=cal.getTimeInMillis();
System.out.println("请输入您的取款年份:");
int w=scan.nextInt();
System.out.println("请输入您的取款月份:");
int x=scan.nextInt();
System.out.println("请输入您的取款日期:");
int y=scan.nextInt();
cal.set(w, x, y);
long day_2=cal.getTimeInMillis();
long day=(day_2-day_1)/(1000*60*60*24);
return day;
}