gpt4 book ai didi

JAVA:如何更新我的 arraylist 值(使用单例),分配另一个值,它不断出错

转载 作者:行者123 更新时间:2023-11-30 08:18:22 24 4
gpt4 key购买 nike

我是 Java 的新手,我正在尝试为一个学校项目做一个 ATM 系统。我不确定如何使用单例更新 ArrayList 值,请帮忙!!!

我正在尝试执行类似 Balance=Balance-withdrawAmount 的操作,但它总是出错。

    public class Users {

private static Users instance = null;
public static List<String> cta = null;
public List<List<String>> accounts = new ArrayList<List<String>>();

private Users() {
accounts.add(Arrays.asList("259853430", "0191", "active","admin","Phil","Anselmo","500000","Citi"));
accounts.add(Arrays.asList("100393938", "0330", "blocked","regular","Trent","Reznor","100000","Citi"));
accounts.add(Arrays.asList("205000800", "0180", "active","regular","Troy","Smith","2006620","Scotiabank"));
accounts.add(Arrays.asList("109000600", "0370", "active","regular","James","Hetfield","5049973","Citi"));
accounts.add(Arrays.asList("202000500", "0350", "active","regular","Tom","Araya","2240070","JPMorgan"));
accounts.add(Arrays.asList("110000200", "1270", "active","regular","Dave","Mustain","3000300","Citi"));
}

public static Users getObject() {
if(instance == null) {
instance = new Users();
}
return instance;
}
}

////////////////////// in a different class


public class UsuarioNormalMenu extends JFrame implements ActionListener{

public void actionPerformed (ActionEvent MenuNormal) {
Users run = Users.getObject();
[ ... ]

if(ok_cancel == -1) {

if(Double.parseDouble(withdrawAmount) > Double.parseDouble(Users.cta.get(6))) {
JOptionPane.showMessageDialog( null,"<html><font size = 3.5><font color = black>"
+ "Inssuficient Funds. " ,"Withdraw",
JOptionPane.WARNING_MESSAGE);
}
else if(Double.parseDouble( withdrawAmount)==Double.parseDouble(Users.cta.get(6))) {
JOptionPane.showMessageDialog( null,"<html><font size = 3.5><font color = black>"
+ "Zero Balance!",
null, JOptionPane.INFORMATION_MESSAGE);
}
else if(Mod==0) {

// THIS IS WHERE IT IS ERRORING OUT, I WANT TO DO SOMETHING LIKE
//Balance=Balance-withdrawAmount; BUT IT DOESNT

double newBalance = Double.parseDouble(Users.cta.get(6)) - (Double.parseDouble(withdrawAmount));
Double.parseDouble(Users.cta.set(6)) = newBalance;


//The error message i get is:
// required: int,String
//found: int
//reason: actual and formal argument lists differ in length
//where E is a type-variable:
//E extends Object declared in interface List

最佳答案

您不能将原始方法的结果分配给一个值(Double.parseDouble() 返回原始double)

Double.parseDouble(Users.cta.set(6)) = newBalance;

应该是这样的

Users.cta.set(6, Double.toString(newBalance));

关于JAVA:如何更新我的 arraylist 值(使用单例),分配另一个值,它不断出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27612800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com