java中调用class的错误在哪里?
Where is the error calling the class in java?
我无法理解为什么在调用 class "Action".
时显示错误
import java.util.*;
public class Banks {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Actions act = new Actions();
System.out.println("How much money would you like to withdrawl?");
double moneygrabber = scan.nextDouble();
act.take(6.24);
}
class Actions {
private double balance = 0;
private double withdrawl;
private double deposit;
void withdrawl(int take) {
this.balance = this.balance - take;
}
}
}
withdrawl
是 Actions
class 中的方法,它接受整数(参数名称是 take 而不是方法名称,您在从 [=23= 调用时使用方法名称] 实例在你的情况下行动)而不是双重。
而不是
act.take(6.24);
使用
act.withdrawl(6);
如果你想传递 double(带小数点的数字),你应该将你的方法参数类型从 int 更改为 double,比如
void withdrawl(double take)
^^^^^^
我无法理解为什么在调用 class "Action".
时显示错误import java.util.*;
public class Banks {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Actions act = new Actions();
System.out.println("How much money would you like to withdrawl?");
double moneygrabber = scan.nextDouble();
act.take(6.24);
}
class Actions {
private double balance = 0;
private double withdrawl;
private double deposit;
void withdrawl(int take) {
this.balance = this.balance - take;
}
}
}
withdrawl
是 Actions
class 中的方法,它接受整数(参数名称是 take 而不是方法名称,您在从 [=23= 调用时使用方法名称] 实例在你的情况下行动)而不是双重。
而不是
act.take(6.24);
使用
act.withdrawl(6);
如果你想传递 double(带小数点的数字),你应该将你的方法参数类型从 int 更改为 double,比如
void withdrawl(double take)
^^^^^^