gpt4 book ai didi

java - 继续收到此错误 : "variable total might not have been initialized"

转载 作者:行者123 更新时间:2023-11-29 07:26:01 26 4
gpt4 key购买 nike

我真的不知道是什么问题,因为 total 已初始化,因为程序总是从情况 1 开始,因为 click 最初等于 1。我必须在哪里初始化它,或者有什么问题?

enterBut.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{

switch(click)
{

case 1:
double subtotal = Double.parseDouble(Atext.getText());
double total = 0.05*Math.round(1.13*subtotal/0.05);
answer.setText("The total will be $" + total + " (tax included). Enter the amount of money the customer gave.");
int click = 2;

case 2:
double money = Double.parseDouble(Atext.getText());
click = 3;
if (money<total)
{
JOptionPane.showMessageDialog(window, "That is not enough money.");
click = 2;
}
}

}

});

最佳答案

你需要把总外开关的定义,像这样:

enterBut.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
double total = 0;
switch(click)
{

case 1:
double subtotal = Double.parseDouble(Atext.getText());
total = 0.05*Math.round(1.13*subtotal/0.05);
answer.setText("The total will be $" + total + " (tax included). Enter the amount of money the customer gave.");
int click = 2;

case 2:
double money = Double.parseDouble(Atext.getText());
click = 3;
if (money<total)
{
JOptionPane.showMessageDialog(window, "That is not enough money.");
click = 2;
}
}

}

});

关于java - 继续收到此错误 : "variable total might not have been initialized",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52613162/

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