[英]Two methods running at the same time
我基本上有一个名为BlueJ的应用程序制造的手机。 它输入电话的持续时间,然后您插入贷方。 每分钟等于一磅。 所以基本上,如果我插入5磅6分钟,它将达到6-5。
在这种情况下,它不起作用。
信用额度是成功的,但是随着信用额度的变化,持续时间将减去新信用额,而不是输入的信用额。
是否有解决此问题的方法或可以同时运行它的方法,或者对于旧值更改之前的值?
问题出在哪里:
credit = credit - duration;
duration = duration - credit;
非常感谢。
public void makePhoneCall()
{
if(credit == 0)
System.out.println("Insert more than 0 credit to make a phone call!");
else {
if(credit >= duration) {
System.out.println("The phone number " + number + " is being dialed for " + duration + " minutes");
credit = credit - duration;
duration = duration - credit;
}
else {
if(credit < duration)
System.out.println("You do not have enough credit to make a phone call! Your credit is " + credit + " pounds");
}
}
我不确定我是否知道您要尝试做的事情,但这是我的理解:
credit = credit - duration;
您正在重新定义“信用”的价值。 但是您想在下面的行中减去“ credit”的原始值。
您可以简单地存储值,然后将其修改到另一个变量中,如下所示:
int oldCredit = credit;
credit = oldCredit - duration;
duration = duration - oldCredit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.