- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Java 程序可以运行,但我不知道如何获得两个帐户的总余额。现在我只是打印出 #####。
这应该是输出:
两个账户的最终余额合计:5255.81
我不想只输入答案。我们必须向程序展示添加两个帐户的所有余额,但我不知道如何编写该代码。
这是我的司机:
public class LineberryRaeChapter13Prog {
public static void main( String args[] )
{
LRSavingsAccount saver1 = new LRSavingsAccount( 2000 );
LRSavingsAccount saver2 = new LRSavingsAccount( 3000 );
LRSavingsAccount.newInterestRate( 0.05 );
System.out.println( "\nMonthly balances for one year with 0.05 annual interest:\n" );
System.out.printf( "%10s%10s%10s%10s%10s\n", "Month", "Account#", "Balance", "Account#", "Balance" );
System.out.printf( "%10s%10s%10s%10s%10s\n", "-----", "--------", "-------", "--------", "-------" );
System.out.printf( "%10s%10s%10s%10s%10s\n", "0","10002", saver1.toString(), "10003", saver2.toString());
for ( int month = 1; month <= 12; month++ )
{
switch (month)
{
case 1:System.out.printf( "\n");
break;
case 2:System.out.printf( "\n");
break;
case 3:System.out.printf( "\n");
break;
case 4:System.out.printf( "\n");
break;
case 5:System.out.printf( "\n");
break;
case 6:System.out.printf( "\n");
break;
case 7:System.out.printf( "\n");
break;
case 8:System.out.printf( "\n");
break;
case 9:System.out.printf( "\n");
break;
case 10:System.out.printf( "\n");
break;
case 11:System.out.printf( "\n");
break;
case 12:System.out.printf( "\n");
break;
}//end switch
String monthLabel = String.format( "%d", month );
saver1.addMonthlyInterest();
saver2.addMonthlyInterest();
System.out.printf( "%10s%10s%10s%10s%10s\n", monthLabel, "10002", saver1.toString(), "10003", saver2.toString());
}//end for
System.out.printf( "%10s%10s\n", "\nFinal balance of both accounts combined:", "######");
}//end main
}//end LineberryRaeChapter13Prog
这是类(class):
public class LRSavingsAccount
{
// interest rate for all accounts
private static double annualInterestRate = 0;
private double Balance;
public static void newInterestRate( double newRate )
{
annualInterestRate = (newRate >= 0 && newRate <= 1.0 ) ? newRate : 0.05;
}//end newInterestRate
// provides account balances
public LRSavingsAccount( double balance )
{
Balance = balance;
}//end Constructor
// calculates the interest for each month
public void addMonthlyInterest()
{
Balance += Balance * ( annualInterestRate / 12.0 );
}//end addMonthlyInterest
// get string representation of SavingAccount
public String toString()
{
return String.format( "$%.2f", Balance );
}//end accesssor
}//end SavingsAccount
最佳答案
在我看来,您可以在“LRSavingsAccount”中为“余额”字段添加一个 getter。所以
公共(public)双 getBalance() {
返回余额;
}
最后,你可以这样做
System.out.println(两个账户的最终余额合计:"+ (saver1.getBalance() + saver2.getBalance());
除非我错过了什么。
关于java - 如何编写代码添加储蓄帐户程序中所有月份余额的总计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32530768/
这可能是一个简单的问题,但我无法弄清楚。 我有两个表中的数据 - 1)贷款 2)还款。我被要求制作一份报告,根据我们当前的投资组合计算每个季度的预期余额。 所以我采取的方法是取贷款表中所有余额的总和(
每次登录时,我都会从 MySQL 数据库获取 $_SESSION[balance] 的值。如何更新客户端浏览器中的值而不每 5 分钟重新加载页面?我认为可以使用 AJAX 来完成? 抱歉,如果这太模糊
我有一个 MySQL 金融交易表。 表格是这样的: +----+-----------+--------+--------+---------+---------+ | id | member_id
我正在开发一个桌面软件,它向用户每次执行主要操作收费。例如,每个 PDF 打印将向用户收取 0.1 美元的费用。 我的软件提供多线程。 . 所以,如果它运行单线程,它就可以正常工作:) 但问题是如果用
嗨,我正在尝试找出应该使用什么 SQL 语句来生成此输出。我尽了最大努力,但我的查询不起作用。谢谢 STUDNO | DEBIT | CREDIT | BALANCE 1001 | 1000
我有下表并需要获得以下输出。 +---------+-----------+------+----------+------------+ | item_id | item_name | qty |
我正在尝试在类里面使用一种收费的方法。方法是这样的: public double chargeFee() { balance -= 10; return balance;
我正在尝试让我的钱包地址余额呈现在我的前端。这是我目前所拥有的。 const [balance, setBalance] = useState(""); const handleWalletBalan
我们正在将 Facebook Credits 实现为 Facebook 上的虚拟货币。 我们已经申请并被列入白名单以访问 Facebook Credits 余额方法,但是从我能够找到的小文档(主要是论
有谁知道如何在 Twilio 中以编程方式检查帐户余额(通过 API)?没有实现吗? 最佳答案 您可以获得Twilio Account details然后使用 请求获取余额subresource_ur
我已经在 PayPal 文档中搜索了两个小时,但找不到答案,甚至搜索了 Google。 在这里检查: https://developer.paypal.com/docs/api/#api-operat
免责声明:我知道这个问题已经被问过很多次了,但我想要的只是一个替代方案。 表格如下: create table Account (Name varchar(20), TType varchar(5)
我需要更正和转换一个函数,检查 btc 余额的 2 个地址,例如(addr 和 addr1),返回的是 json 值,我需要指定我不太了解 golang..需要帮助! func balance(add
当我运行它时,我得到“TypeError:无法读取未定义的属性‘balance’。”我刚开始学习 Node,我不确定自己做错了什么。请帮忙。 跟作用域有关系吗?我该如何解决? //create an
以下 Vanilla JS 示例通过 Phantom 钱包连接到 Solana 区 block 链并断开连接。 连接成功并获取公共(public)地址。 尝试使用 JSON-RPC 请求获取钱包余额和
我是一名优秀的程序员,十分优秀!