如何开发计算储蓄账户每月余额的算法

发布于 2024-12-09 00:12:43 字数 1507 浏览 0 评论 0原文

问题说得好。开发一种算法来计算储蓄帐户中的每月余额。您可以每月进行交易存款或取款。利息在每个月初添加到帐户中。月利率是年利率除以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-12-16 00:12:43

首先,您可能会考虑将 int 存款值放入数组中。其次,在循环中检索值。使用 Calendar 获取月份的名称。最后,在循环中进行滚动计算:如下所示:

float balance = 0;
for (int i=0; i<12; i++){
    balance *= 1.035;
    balance += deposit[i];
    System.out.println("Balance this month is:" + balance);
}

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:

float balance = 0;
for (int i=0; i<12; i++){
    balance *= 1.035;
    balance += deposit[i];
    System.out.println("Balance this month is:" + balance);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文