对于一个项目,我需要在主方法中调用方法 getBill 。 getBill返回一个int值(bill),但是当我这样声明时:
getBill(qty);
我遇到一个错误。我是使用方法的新手,是否正确声明了方法本身?有什么方法可以不必使用方法来执行getBill的操作?
这是我需要调用该方法的代码的一部分:
while (true) {
line = bc.readLine();
if (line == null)
break;
billdata = line.split(",");
accs = Integer.parseInt(billdata[0]);
type = billdata[1];
qty = Integer.parseInt(billdata[2]);
company = billdata[3];
if (accNo == accs) {
System.out.println("Your RHY Telecom account has been found.");
System.out.printf("%5s",accs);
System.out.printf("%24s",qty);
System.out.printf("%10s",type);
System.out.printf("%20s",company);
System.out.println("Your current charges are: ");
}
}
}
这是方法本身:
public static int getBill(int plan,int bill,int qty,String[] accountdata,String line) throws Exception {//getting details from text file number 2,then computing the bill
BufferedReader bf = new BufferedReader(new FileReader("res/account-Info-Final1.txt"));
accountdata = line.split(",");
plan = Integer.parseInt(accountdata[4]);
bill = 0;
int smslimit = Integer.parseInt(accountdata[5]);
int calllimit = Integer.parseInt(accountdata[6]);
double datalimit = Double.parseDouble(accountdata[7]);
if (qty > smslimit) {
bill = (qty * 2) + plan;
} else if (qty > calllimit) {
bill = (qty * 5) + plan;
} else if (qty > datalimit) bill = (qty * 3) + plan;
else if (qty <= smslimit || qty <= datalimit || qty <= calllimit){
bill += plan;
}
return bill;
}
}