I am trying to complete a program that reads input from a file and calculates the bill for different customers and then adds all of the total bills together. It must take in to account a 5% discount if there is work on over 1000 acres in addition to a 10% discount for any bill that exceeds $1500. I believe my first module of "public static double computBill" is correct, but I do not know how to file data in to the while loop in order to give discounts and I know that my second module of the "void main(string..." is incorrect. Or they could both be incorrect. Any help is much appreciated. Here is what I have so far:
Assuming your file can contain multiple lines for one client, there is no way to calculate the discount based on total bill until you have processed all the lines in the file. Therefore you are going to have to accumulate information for each client as you go through the file. You don't say whether the "work on 1000 acres" has to be on one line in the file or not; if it does, you can calculate that in your "computeBill" routine, which appears to be called for one line. But after you're done accumulating things for all clients (either totalling them as you go or keeping an object per line organized by client), then you can see what their total bill is to give them the 10% discount.
Joined: Apr 17, 2012
Thanks Ralph! However, upon working on this more, I realized that I was focusing on the wrong problem, as I should have fixed the first module of computeBill first. Now that it is REALLY correct, I am having trouble understanding what my compiler is trying to tell me when it says "cannot find symbol - method grossCharge(int,int)" From what I understand, the code in the while loop needs to look just as it is (or if someone can tell otherwise, please let me know. Here is what I have now:
public class farmBill
NumberFormat fmt = NumberFormat.getCurrencyInstance();
public static double computeBill
(int type, int acres, double computeBill, double acresDiscount,
double costDiscount, double grossCharge)
if (acres <= 0 || type < 4 || type > 1)
return -1 ;
computeBill = acres*1;
computeBill = acres*2;
computeBill = acres*4;
computeBill = acres*6;
computeBill = -1;
if (acres > 1000)
acresDiscount = -(acres * .05);
if (computeBill > 1500)
costDiscount = -(computeBill * .1);
return grossCharge = (computeBill + acresDiscount + costDiscount);
public static void main(String  args) throws IOException
File input = new File("spraying.txt");
The compiler is saying that you've made a call to method 'grossCharge' which takes 2 int arguments, but there's no definition found for that method. In short, you'll have to define that method.
Apart from that, I have some concerns about your code:
1) The instance variable fmt is - well - instance variable. So, you cannot use it in any static method. You are using it in main method, which will give you a compile time error.
2) Please follow Java coding convention.
3) In computeBill method, apart from type and acres, all other variables are simply used either intermediate value holders, or for holding the output. Their input values are never being used. So, why those variables are part of method signature? You can rewrite that method with accepting only two int variables.
4) In main method, you are not assigning clientNumber, type and acres variables. Please note that local variables in method are not initialized with default values. So, once you get rid of your initial compile time errors, you'll face further errors regarding usage of these variables without initialization.
5) You are invoking scan.close in main method after the return statement. This scan.close will never happen since it is after main statement.
6) You are returning a String from main, but main method is void.
7) In your if condition, there is a part : type < 4 || type > 1. This will always return true. What exactly are you trying to achieve?
I know that at this stage, you may not be aware of all these problems, but this questionnaire would be a nice exercise for you