Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编程储蓄账户Java表以显示2的增量_Java_Jsp_Html Table - Fatal编程技术网

编程储蓄账户Java表以显示2的增量

编程储蓄账户Java表以显示2的增量,java,jsp,html-table,Java,Jsp,Html Table,我正在为我的班级开发一个网络应用程序。基本上,我必须编写java和jsp来创建一个提供以下.jsp输出的站点(前面是一个.jsp页面,该页面要求余额、速率和周期)。我现在正在为它编写java,并试图用java类创建一个html表 我要解决的问题是,使表格显示的是速率(行)和周期(列)的标准偏差2。而不是仅仅添加所有期间和费率的所有信息。我如何缩小范围 注意:我知道我表中的代码一点也不正确,但我认为其他一切都可以 到目前为止,我的代码是: package SavingAcct;

我正在为我的班级开发一个网络应用程序。基本上,我必须编写java和jsp来创建一个提供以下.jsp输出的站点(前面是一个.jsp页面,该页面要求余额、速率和周期)。我现在正在为它编写java,并试图用java类创建一个html表

我要解决的问题是,使表格显示的是速率(行)和周期(列)的标准偏差2。而不是仅仅添加所有期间和费率的所有信息。我如何缩小范围

注意:我知道我表中的代码一点也不正确,但我认为其他一切都可以

到目前为止,我的代码是:

    package SavingAcct;

    import java.text.*;

    public class savingsAccount {

private double rate;
private double currentBalance;
private int term;

public savingsAccount() {

    this.rate = 0.00;
    this.currentBalance = 0.00;
    this.term = 0;


}

public savingsAccount(double rate, double currentBalance, int term) {

    this.rate = rate;
    this.currentBalance = currentBalance;
    this.term = term;


}

/**
 * @return the term
 */
public int getTerm() {
    return term;
}

/**
 * @param term the term to set
 */
public void setTerm(int term) {
    this.term = term;
}

/**
 * @return the rate
 */
public double getRate() {
    return rate;
}

/**
 * @param rate the rate to set
 */
public void setRate(double rate) {
    this.rate = rate;
}

/**
 * @return the balance
 */
public double getBalance() {

    return currentBalance;
}

/**
 * @param balance the balance to set
 */
public void setBalance(double balance) {
    this.currentBalance = balance;
}

public String doSavingsAccount() {
    String htmlSavingsTable = "";


    NumberFormat cf = NumberFormat.getCurrencyInstance();
    NumberFormat pf = NumberFormat.getPercentInstance();

    //start the html table
    htmlSavingsTable = "<table border='2'>";
    //create a table heading
    htmlSavingsTable += "<tr>";
    htmlSavingsTable += "<td><b>  -  </b></td>";
    htmlSavingsTable += "<td><b>" + (term-2) + "</b></td>";
    htmlSavingsTable += "<td><b>" + (term-1) + "</b></td>";
    htmlSavingsTable += "<td><b>" + term + "</b></td>";
    htmlSavingsTable += "<td><b>" + (term+1) + "</b></td>";
    htmlSavingsTable += "<td><b>" + (term+2) + "</b></td>";
    htmlSavingsTable += "</tr>";

    for (double rate = this.getRate()-2; rate <= getRate()+2;){


        // start html table row for 
        htmlSavingsTable += "<tr>";
        // add rate to row
        htmlSavingsTable += "<td><b>" + pf.format(rate-2) + "</b></td>";
        // add monthly payment to row
        htmlSavingsTable += "<td><b>" + cf.format(getNewBalance())+     "</b></td>";
        // end the row
        htmlSavingsTable += "</tr>";


    }
    // end the table
    htmlSavingsTable += "</table>";

    return htmlSavingsTable;

}

public double getNewBalance() {
    double newBalance;
    newBalance = currentBalance * (Math.pow((1+rate), term));
    return newBalance;
}


    }
package SavingAcct;
导入java.text.*;
公共类储蓄帐户{
私人双费率;
私人双电流平衡;
专用术语;
公共储蓄账户(){
该比率=0.00;
该电流平衡=0.00;
该项=0;
}
公共储蓄账户(双倍利率、双倍余额、整数期限){
这个比率=比率;
此.currentBalance=currentBalance;
这个术语=术语;
}
/**
*@返回术语
*/
公共int getTerm(){
回报期;
}
/**
*@param term要设置的术语
*/
公共无效设置项(整数项){
这个术语=术语;
}
/**
*@返回速率
*/
公共双速率(){
回报率;
}
/**
*@param rate要设置的速率
*/
公共无效设置率(双倍率){
这个比率=比率;
}
/**
*@归还余额
*/
公共双getBalance(){
回流平衡;
}
/**
*@param balance要设置的余额
*/
公共余额(双倍余额){
这个.currentBalance=平衡;
}
公共字符串doSavingsAccount(){
字符串htmlSavingsTable=“”;
NumberFormat cf=NumberFormat.getCurrencyInstance();
NumberFormat pf=NumberFormat.getPercentInstance();
//启动html表
htmlSavingsTable=“”;
//创建一个表标题
htmlSavingsTable+=“”;
htmlSavingsTable+=“-”;
htmlSavingsTable++(术语2)+;
htmlSavingsTable++(术语1)+;
htmlSavingsTable+=“”+术语+“”;
htmlSavingsTable++(术语+1)+;
htmlSavingsTable++=“”+(术语+2)+“”;
htmlSavingsTable+=“”;

for(double rate=this.getRate()-2;rate首先需要在for循环中增加
rate
,然后需要迭代每个可能的
术语,并将
term
rate
传递给
getNewBalance()
函数

编辑:代码

package acme.savingacct;

import java.text.NumberFormat;

public class SavingsAccount {
    private transient double startingRate;
    private transient double currentBalance;
    private transient int startingTerm;

    public SavingsAccount(final double startingRate,
            final double currentBalance, final int startingTerm) {
        this.startingRate = startingRate;
        this.currentBalance = currentBalance;
        this.startingTerm = startingTerm;
    }

    public SavingsAccount() {
        this.startingRate = 0.0;
        this.currentBalance = 0.0;
        this.startingTerm = 0;
    }

    /**
     * @return the term
     */
    public final int getStartingTerm() {
        return startingTerm;
    }

    /**
     * @param term
     *            the term to set
     */
    public void setStartingTerm(final int term) {
        this.startingTerm = term;
    }

    /**
     * @return the rate
     */
    public final double getStartingRate() {
        return startingRate;
    }

    /**
     * @param rate
     *            the rate to set
     */
    public void setStartingRate(final double rate) {
        this.startingRate = rate;
    }

    /**
     * @return the balance
     */
    public final double getBalance() {
        return currentBalance;
    }

    /**
     * @param balance
     *            the balance to set
     */
    public void setBalance(final double balance) {
        this.currentBalance = balance;
    }

    @Override
    public String toString() {
        final StringBuffer htmlSavingsTable = new StringBuffer(1024);
        final NumberFormat currFmt = NumberFormat.getCurrencyInstance();
        final NumberFormat pctFmt = NumberFormat.getPercentInstance();

        // start the html table & create a table heading
        htmlSavingsTable.append("<table border='2'>\n  <tr>\n"
                + "    <th>  -  </th>\n");

        for (int term = getStartingTerm(); term < getStartingTerm() + 5; term++) {
            htmlSavingsTable.append("    <th>" + term + "</th>\n");
        }

        htmlSavingsTable.append("  </tr>\n");

        for (double rate = getStartingRate(); rate < getStartingRate() + 5.0; rate++) {
            // start html table row for rate & add rate to row
            htmlSavingsTable.append("  <tr>\n    <th>"
                    + pctFmt.format(rate / 100.0) + "</th>\n");

            // add monthly payment to row
            for (int term = getStartingTerm(); term < getStartingTerm() + 5; term++) {
                htmlSavingsTable
                        .append("    <td>"
                                + currFmt.format(getNewBalance(rate, term))
                                + "</td>\n");
            }

            // end the row
            htmlSavingsTable.append("  </tr>\n");
        }

        // end the table
        htmlSavingsTable.append("</table>");

        return htmlSavingsTable.toString();
    }

    /**
     * @param aRate
     *            the rate
     * @param aTerm
     *            the term
     * @return the calculated balance
     */
    public double getNewBalance(final double aRate, final int aTerm) {
        double newBalance;
        newBalance = currentBalance * (Math.pow((1 + aRate / 100.0), aTerm));
        return newBalance;
    }

    /**
     * For testing purpose ..
     * 
     * @param args
     */
    public static void main(final String[] args) {
        final SavingsAccount sacc = new SavingsAccount(5.0, 1000.0, 12);
        System.out.println(sacc);
    }

}
package acme.savingacct;
导入java.text.NumberFormat;
公共类储蓄帐户{
私人瞬时双启动率;
专用瞬态双电流平衡;
私人临时启动期限;
公共储蓄账户(最终双倍启动率,
最终双电流平衡,最终整数启动期限){
this.startingRate=启动速率;
此.currentBalance=currentBalance;
this.startingTerm=startingTerm;
}
公共储蓄账户(){
该启动率=0.0;
该电流平衡=0.0;
这个.startingTerm=0;
}
/**
*@返回术语
*/
公共最终整数getStartingTerm(){
返回起始条件;
}
/**
*@param术语
*设定的术语
*/
公共无效设置起始期限(最终整数期限){
this.startingTerm=术语;
}
/**
*@返回速率
*/
公共最终双重启动率(){
返回启动率;
}
/**
*@param速率
*设定的利率
*/
公共资金(最终双倍费率){
这个。启动速率=速率;
}
/**
*@归还余额
*/
公共最终双getBalance(){
回流平衡;
}
/**
*@param余额
*平衡
*/
公共账户余额(最终双倍余额){
这个.currentBalance=平衡;
}
@凌驾
公共字符串toString(){
最终StringBuffer htmlSavingsTable=新StringBuffer(1024);
final NumberFormat currFmt=NumberFormat.getCurrencyInstance();
final NumberFormat pctFmt=NumberFormat.getPercentInstance();
//启动html表格并创建表格标题
htmlSavingsTable.append(“\n\n”
+“-\n”);
对于(int term=getStartingTerm();term