我总是被告知永远不要代表钱double或float类型,这次我向你提出问题:为什么?
我确信有一个很好的理由,我根本不知道它是什么.
大家好,我是计算机系统开发的第一年,所以我对Java很新,掌握了基础知识!
对于我的第一项任务,我必须为燃气公司创建一个燃气表系统,以允许员工创建新的客户账户并修改名称和单位成本等数据,并从他们的账户中存入(存入)资金.
我已经创建了我的构造函数,甚至添加了一个重载方法,虽然我在启动我的一个名为deposit的方法时遇到了问题,这应该从用户帐户获取资金,而其他方法如recordUnits允许员工输入燃气表读数显示客户使用了多少单位,并更新客户账户的余额,这基本上是客户欠公司的.
在尝试启动存款方法时使用预设信息测试程序时,我得到了这个
Account.deposit(Double.MAX_VALUE);
Run Code Online (Sandbox Code Playgroud)
我不太清楚这意味着什么,似乎无法找到过去它!如果这已经发布,我会道歉,虽然我已经四处寻找合适的答案无济于事.
测试数据和代码如下所示:
public class TestGasAccount
{
public static void main (String [] args)
{
GasAccount Account = new GasAccount (223,"Havana","TQ",1000);
Account.getAccNo();
Account.getName();
Account.getAddress();
Account.getUnits();
Account.getBalance();
Account.recordUnits(1000);
Account.getUnits();
Account.getBalance();
Account.deposit(Double.MAX_VALUE);
}
}
Run Code Online (Sandbox Code Playgroud)
打破
public class GasAccount
{
private int intAccNo;
private String strName;
private String strAddress;
private double dblBalance;
private double dblUnits;
protected double dblUnitCost = 0.02;
public GasAccount(int intNewAccNo,String strNewName,String strNewAddress,double dblNewUnits)
{
intAccNo = intNewAccNo;
strName = strNewName;
strAddress = …Run Code Online (Sandbox Code Playgroud) 我目前正在为我的应用程序中的ContentProvider编写测试用例(这是一个支票簿录制应用程序),并且在比较双值时我遇到了测试失败.说明这一点的最好方法是使用代码.我有这个函数返回要插入数据库的帐户对象的ContentValues:
private ContentValues getAccountContentValues(){
String testName = "Capital One";
double testStartingBalance = 3000.00;
ContentValues accountValues = new ContentValues();
accountValues.put(AccountEntry.COLUMN_NAME, testName);
accountValues.put(AccountEntry.COLUMN_BALANCE, testStartingBalance);
return accountValues;
}
Run Code Online (Sandbox Code Playgroud)
在函数内部,testInsertReadProvider()我有以下代码,以插入该帐户:
// Get Account values and write them
ContentValues accountValues = getAccountContentValues();
Uri accountInsertUri =
mContext.getContentResolver().insert(AccountEntry.CONTENT_URI, accountValues);
long accountRowId = ContentUris.parseId(accountInsertUri);
// Verify we got a row back
assertTrue(accountRowId > 0);
// A cursor is the primary interface to the query results
Cursor cursor = mContext.getContentResolver().query(
AccountEntry.CONTENT_URI, // Table name
null, // columns …Run Code Online (Sandbox Code Playgroud) 我只是好奇是否有人知道 JSR 354 是否会作为任何未来 JDK 的一部分正式实现。
当我在线搜索 JDK 11 文档时 - 它看起来不像Monetary并且MonetaryAmount不包含类。但是在 jsr354-ri 下的 Github 中存在 JSR 354 的实现。
如果我不想遵循参考实现,这是否意味着我可以编写自己的实现?我的目的是支持其他货币,例如没有官方 ISO 认可但众所周知的中国人民币(离岸)CNH。
谢谢,
Java有免费的视频会议API吗?这是一个远程医疗项目.我必须从Java应用程序(患者端)到医生端的Web客户端进行通信.
我有这门课:
\nclass Product {\n public double price;\n\n public Product(double price) {\n this.price = price;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n还有一张地图:
\nMap<Product, Integer> products = new HashMap<>();\nRun Code Online (Sandbox Code Playgroud)\n其中包含添加的几种产品,如下所示:
\nproducts.put(new Product(2.99), 2);\nproducts.put(new Product(1.99), 4);\nRun Code Online (Sandbox Code Playgroud)\n我想使用流计算所有乘积的总和乘以值?我试过:
\ndouble total = products.entrySet().stream().mapToDouble((k, v) -> k.getKey().price * v.getValue()).sum();\nRun Code Online (Sandbox Code Playgroud)\n但它无法编译,我得到 \xe2\x80\x9c无法解析方法getValue()\xe2\x80\x9d。
我预计:
\n(2.99 * 2) + (1.99 * 4) = 5.98 + 7.96 = 13.94\nRun Code Online (Sandbox Code Playgroud)\n public class Account {
public double balance ;
public double deposite;
public double withdraw;
public Account(double balance) {
this.balance = balance;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getDeposite() {
balance = balance + deposite;
return deposite;
}
public void setDeposite(double deposite) {
this.deposite = deposite;
}
public double getWithdraw() {
return withdraw;
}
public void setWithdraw(double withdraw) {
this.withdraw = withdraw;
if(withdraw <= balance){
balance = balance …Run Code Online (Sandbox Code Playgroud)