如何开发计算储蓄账户每月余额的算法
问题说得好。开发一种算法来计算储蓄帐户中的每月余额。您可以每月进行交易存款或取款。利息在每个月初添加到帐户中。月利率是年利率除以 12。
到目前为止,这是我的代码。我不确定,但我有一种感觉,我做错了事情。请帮忙。
import java.util.Scanner;
/**
Program to calculate the transaction you make..
**/
public class Ch4ProblemTwo
{
public static final double INTEREST_RATE = 1.5; //150% per month
public static void main(String[] args)
{
int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12;
System.out.println("Enter the amount you deposit each month ");
Scanner keyboard = new Scanner(System.in);
System.out.print("January ");
n1= keyboard.nextInt();
System.out.print("Februray ");
n2= keyboard.nextInt();
System.out.print("March ");
n3= keyboard.nextInt();
System.out.print("April ");
n4= keyboard.nextInt();
System.out.print("May ");
n5= keyboard.nextInt();
System.out.print("June ");
n6= keyboard.nextInt();
System.out.print("July ");
n7= keyboard.nextInt();
System.out.print("August ");
n8= keyboard.nextInt();
System.out.print("September ");
n9= keyboard.nextInt();
System.out.print("October ");
n10= keyboard.nextInt();
System.out.print("November ");
n11= keyboard.nextInt();
System.out.print("December ");
n12= keyboard.nextInt();
System.out.println("This entire year you have deposite");
System.out.print(n1+3.5%+n2+3.5%+n3+3.5%+n3+3.5%+n4+3.5%+n5+3.5%+n6+3.5%+n7+3.5%+n8+3.5%+n9+3.5%+n10+3.5%+n11+3.5%+n12+3.5);
}
}
well the problem say. Develop an algorithm for computing the month-by-month balance in your saving account. you can make on transaction a deposit or withdrawal each month. interest is added to the account at the beginning of each month. The monthly interest rate is the yearly percentage rate divided by 12.
This is my code so far. I'm not sure, but I have a feeling that I'm doing things wrong. Please help.
import java.util.Scanner;
/**
Program to calculate the transaction you make..
**/
public class Ch4ProblemTwo
{
public static final double INTEREST_RATE = 1.5; //150% per month
public static void main(String[] args)
{
int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12;
System.out.println("Enter the amount you deposit each month ");
Scanner keyboard = new Scanner(System.in);
System.out.print("January ");
n1= keyboard.nextInt();
System.out.print("Februray ");
n2= keyboard.nextInt();
System.out.print("March ");
n3= keyboard.nextInt();
System.out.print("April ");
n4= keyboard.nextInt();
System.out.print("May ");
n5= keyboard.nextInt();
System.out.print("June ");
n6= keyboard.nextInt();
System.out.print("July ");
n7= keyboard.nextInt();
System.out.print("August ");
n8= keyboard.nextInt();
System.out.print("September ");
n9= keyboard.nextInt();
System.out.print("October ");
n10= keyboard.nextInt();
System.out.print("November ");
n11= keyboard.nextInt();
System.out.print("December ");
n12= keyboard.nextInt();
System.out.println("This entire year you have deposite");
System.out.print(n1+3.5%+n2+3.5%+n3+3.5%+n3+3.5%+n4+3.5%+n5+3.5%+n6+3.5%+n7+3.5%+n8+3.5%+n9+3.5%+n10+3.5%+n11+3.5%+n12+3.5);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您可能会考虑将
int
存款值放入数组中。其次,在循环中检索值。使用 Calendar 获取月份的名称。最后,在循环中进行滚动计算:如下所示:First you might consider putting the
int
deposit values in an array. Second, retrieve the values in a loop. Use Calendar to get the names of the months. Finally, in a loop do a rolling calculation: something like this: