Saver 1
New Monthly Savings Balance After Interest: 27958.33
Saver 2
New Monthly Savings Balance After Interest: 4933.33
Saver 1
New Monthly Savings Balance After Interest: 49240.28
Saver 2
New Monthly Savings Balance After Interest: 6431.11
再次感谢您!
public class SavingsAccountDriver {
public static void main(String[] args) {
SavingsAccount saver1 = new SavingsAccount();
SavingsAccount saver2 = new SavingsAccount();
saver1.setsavingsBalance(2000);
saver2.setsavingsBalance(3000);
SavingsAccount.modifyInterestRate(0.04);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.printf("\nSaver 1\nNew Monthly Savings Balance After Interest: %.2f",saver1.getsavingsBalance());
System.out.printf("\nSaver 2\nNew Monthly Savings Balance After Interest: %.2f",saver2.getsavingsBalance());
SavingsAccount.modifyInterestRate(0.05);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.printf("\nSaver 1\nNew Monthly Savings Balance After Interest: %.2f",saver1.getsavingsBalance());
System.out.printf("\nSaver 2\nNew Monthly Savings Balance After Interest: %.2f",saver2.getsavingsBalance());
}
public class SavingsAccount {
public static double annualInterestRate;
public double savingsBalance;
/*
* Constructor
* */
public SavingsAccount() {
annualInterestRate = 0;
savingsBalance = 0;
}
/*
* Overloaded
* */
public SavingsAccount(double savingsBalance) {
this.savingsBalance = savingsBalance;
}
/*
* Calculates Monthly Interest from savings balance and interest rate
* */
public void calculateMonthlyInterest() {
savingsBalance += savingsBalance*annualInterestRate/12;
}
/*
* Interest Rate modifier
* */
public static void modifyInterestRate(double newInterestRate) {
annualInterestRate = newInterestRate;
}
/*
* Returns new Savings Balance
* */
public double getsavingsBalance() {
return savingsBalance;
}
/*
* Sets new savings balance after interest
* */
public void setsavingsBalance(double savingsBalance) {
this.savingsBalance = savingsBalance;
}
/*
* Returns Interest Rate
* */
public double getannualInterestRate() {
return annualInterestRate;
}
}
public class SpecialSavings extends SavingsAccount {
public SpecialSavings() {
annualInterestRate = 0;
savingsBalance = 0;
}
public SpecialSavings(double savingsBalance) {
super(savingsBalance);
}
public void calculateMonthlyInterest() {
if(getsavingsBalance()>10000) {
modifyInterestRate(10);
}else {
modifyInterestRate(4);
}
super.calculateMonthlyInterest();
}
public void deposit(double amount) {
savingsBalance+=amount;
}
public void withdraw(double amount) {
savingsBalance-=amount;
}
}
public class SpecialSavingsDriver {
public static void main(String[] args) {
SpecialSavings saver1 = new SpecialSavings();
SpecialSavings saver2 = new SpecialSavings();
saver1.setsavingsBalance(2000);
saver2.setsavingsBalance(3000);
SavingsAccount.modifyInterestRate(0.04);
saver1.deposit(13000);
saver1.deposit(250);
saver2.deposit(350);
saver2.deposit(350);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.printf("\nSaver 1\nNew Monthly Savings Balance After Interest: %.2f",saver1.getsavingsBalance());
System.out.printf("\nSaver 2\nNew Monthly Savings Balance After Interest: %.2f",saver2.getsavingsBalance());
saver1.withdraw(1000);
saver1.withdraw(100);
saver2.withdraw(100);
saver2.withdraw(10);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.printf("\nSaver 1\nNew Monthly Savings Balance After Interest: %.2f",saver1.getsavingsBalance());
System.out.printf("\nSaver 2\nNew Monthly Savings Balance After Interest: %.2f",saver2.getsavingsBalance());
}
}
我觉得问题出在这条线上。
保存平衡*年度间战略/12;
它将像这样执行:-
(savingsBalance*annualInterestRate)/12;
= (multipliedValue)/12;
= result
savingsBalance*(annualInterestRate/12);
本文向大家介绍Android程序报错程序包org.apache.http不存在问题的解决方法,包括了Android程序报错程序包org.apache.http不存在问题的解决方法的使用技巧和注意事项,需要的朋友参考一下 Android Studio 2.1中使用 Android SDK 6.0(API 23),加载融云Demo时,报错: 解决办法: Android 6.0(api 23)已经不支持
本文向大家介绍Maven install 报错"程序包不存在"问题的解决方法,包括了Maven install 报错"程序包不存在"问题的解决方法的使用技巧和注意事项,需要的朋友参考一下 概述 在mvn clean install时,控制台各种报错,大概有: java:[8,52] 程序包com.xxx不存在 java:[98,27] 找不到符号 符号: 类 XXX 位置: 类XXX [ERROR
我有一个java的家庭作业。我的任务是建立一个可以取款、存款和查询余额的银行。我的问题是在存款和取款后我无法更新我的余额...我已经尝试了我能做的一切,但仍然无法得到逻辑。有人可以帮助添加到我的程序中吗...谢谢 ---------------------------------主要的--------------------------------
本文向大家介绍WIN32程序获取父进程ID的方法,包括了WIN32程序获取父进程ID的方法的使用技巧和注意事项,需要的朋友参考一下 学过windows程序设计的人都知道,windows中的进程是可以有父子关系的,拥有父子关系的进程,一旦父进程结束,子进程有会随之退出。但是如果进程之间没有父子关系,我们如何让子进程在父进程退出是也同时跟着退出呢?方法有很多,本文介绍其中的一种利用父进程ID的方案,实
本文向大家介绍APK程序获取system权限的方法,包括了APK程序获取system权限的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了APK程序获取system权限的方法。分享给大家供大家参考。具体如下: 最近项目需要,用NDK编程,遇到了些问题,在访问底层的设备时,没有权限,后来就在网上查找了资料,一开始还以为有root权限,找来找去,弄来弄去,程序都获取不到root权限,后来找
我启动了默认JavaFX项目。这是我的结构: 这是个例外: 我真的不知道我该怎么办。我已经检查了关于这个问题的问题,它对我没有帮助,即使我改变了项目的结构,就像这个问题JavaFX InvocationTargetException一样