| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 715 人关注过本帖
标题:求大神帮忙写一个初级java(内附题目)
只看楼主 加入收藏
a2513536a
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-11-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求大神帮忙写一个初级java(内附题目)
Write a Java program for a bank that will calculate the monthly interest earned on a cashdeposit. The user enters the amount deposited, the term, and interest rate. The program willthen display a table listing for the month, interest, total interest, and account balance for eachperiod. For example, if the amount deposited is $2000.00, the term is 6 months and theinterest rate is 2%, the following output will be displayed:
编写一个Java程序,将计算银行每月的现金存款所赚取的利息。用户输入存入的金额,期限,利率。该计划将显示表中列出的为一个月,利息,利息总额,帐户余额为每个时期。例如,如果存入的金额是$ 2000.00,期限为6个月,利率为2%,将显示以下输出:
程序代码:
Period Interest Total Interest Total Balance
1        6.66      6.66           2006.66
2        6.69      13.35          2013.35
3        6.71      20.06         2020.06
4        6.74      26.80         2026.80
5        6.75      33.55         2033.55
6        6.78      40.33        2040.33

Initial deposit: $2000.00
Total Interest: $40.33
Total Balance: $2040.33
搜索更多相关主题的帖子: java 银行 following interest account 
2011-11-22 14:43
a2513536a
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-11-22
收藏
得分:0 
在校学生,啥也不会。。。求大神帮助。。。
2011-11-22 14:49
xiaoqi0110
Rank: 2
等 级:论坛游民
帖 子:55
专家分:52
注 册:2010-8-15
收藏
得分:10 
这是那个傻逼出的题,
2011-11-23 09:58
youlishen
Rank: 2
等 级:论坛游民
帖 子:6
专家分:14
注 册:2011-9-25
收藏
得分:10 
我今天晚上写了个,发出来,这是我写的,你自己再修改补充吧...
程序代码:
import java.text.DecimalFormat;
import java.util.Scanner;

public class BankCalRate {
    double amount;
    double rate;
    int term;

    BankCalRate() {
        this.amount = 0;
        this.term = 1;
        this.rate = 0;
    }

    BankCalRate(double amount, int term) {
        this.amount = amount;
        this.term = term;
        this.rate = 0.005;
    }

    BankCalRate(double amount, int term, double rate) {
        this.amount = amount;
        this.term = term;
        this.rate = rate / term;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public double getAmount() {
        return amount;
    }

    public void setTerm(int term) {
        this.term = term;
    }

    public int getTerm() {
        return term;
    }

    public void setRate(double rate) {
        this.rate = rate / term;
    }

    public double getRate() {
        return rate;
    }

    /**
     * 提供给用户的信息输入,以便用户可以了解其相应信息的结果
     */
    public void ImfoInput() {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入计算的金额:");
        amount = scan.nextDouble();
        System.out.println("请输入该金额存款时间长度:");
        term = scan.nextInt();
        System.out.println("请输入目前的利息率:");
        rate = scan.nextDouble() / term;
    }

    public void ExceptRateInput() {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入计算的金额:");
        amount = scan.nextDouble();
        System.out.println("请输入该金额存款时间长度:");
        term = scan.nextInt();
    }

    /**
     * 计算每个月的后的总金额
     * 
     * @return
     */
    double[] CalA() {
        double[] resulta = new double[term + 1];
        resulta[0] = amount * (1 + rate);

        for (int i = 1; i < term; i++) {
            resulta[i] = resulta[i - 1] * (1 + rate);
        }
        return resulta;
    }

    /**
     * 计算每个月的后的利息
     * 
     * @return
     */
    double[] CalR() {
        double[] resultr = new double[term];
        resultr[0] = amount * rate;
        double sumrate = 0;
        for (int i = 1; i < term; i++) {
            resultr[i] = (amount + sumrate) * rate;
            sumrate += resultr[i - 1];
        }
        return resultr;
    }

    /**
     * 计算每个月总金额与利息 返回一个两行的数组result[2][] 第一行result[0]是每个月后的总金额数组
     * 第二行result[1]是每个月的利息数组
     * 
     * @return result[2][]
     * 
     */
    public double[][] Calculate() {
        double[][] result = new double[2][];
        result[0] = CalA();
        result[1] = CalR();
        return result;
    }

    public void output(double[] resulta, double[] resultr) {
        double sumrate = 0;
        System.out.println("输出结果如下:");
        DecimalFormat df = new DecimalFormat(" 0.00 ");
        for (int i = 0; i < term; i++) {
            sumrate += resultr[i];
            System.out.println((i + 1) + "\t" + df.format(resultr[i]) + "\t"
                    + df.format(sumrate) + "\t" + df.format(resulta[i]));
        }
        System.out.println("原始金额:"+df.format(resulta[0]-resultr[1]));
        System.out.println("到期后的利息:"+df.format(resulta[term-1]-resulta[0]+resultr[0]));
        System.out.println("到期后的总金额:"+df.format(resulta[term-1]));
    }

    public static void main(String[] args) {
        BankCalRate bcr = new BankCalRate(2000, 6, 0.02);
        double[][] result = bcr.Calculate();
        bcr.output(result[0], result[1]);
        int months=bcr.getTerm();
        //System.out.println("原始金额:"+(result[0][0]-result[1][0]));
        //System.out.println("到期后的利息:"+(result[0][months-1]-result[0][0]+result[1][0]));
        //System.out.println("到期后的总金额:"+result[0][months-1]);
        Scanner scan = new Scanner(System.in);
        String str;
        while (true) {
            System.out.println("确定要输入金额?Y or N:");
            str = scan.next();
            if (str.equalsIgnoreCase("n") || str.equalsIgnoreCase("no"))
                break;
            System.out.println("默认利率是0.005,您选择默认的吗?Y or N:");
            str = scan.next();
            if (str.equalsIgnoreCase("y") || str.equalsIgnoreCase("yes")) {

                bcr.ExceptRateInput();
                result = bcr.Calculate();
                bcr.output(result[0], result[1]);
            } else {

                bcr.ImfoInput();
                result = bcr.Calculate();
                bcr.output(result[0], result[1]);
            }
        }
    }

}


[ 本帖最后由 youlishen 于 2011-11-24 23:01 编辑 ]
2011-11-24 22:49
快速回复:求大神帮忙写一个初级java(内附题目)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018551 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved