# Attempting to calculate a budget and using public static double method(...)

• October 1st, 2013, 10:06 PM
taze
Attempting to calculate a budget and using public static double method(...)
I'm trying to get back the answer in my public static double method. Every time I try to compile, however, it doesn't recognize this: (double kms, double fuelEfficiency, double carIns) and says I am missing a class. I'm completely stuck why I can't get it to work.

Note: I need to actually do a lot more calculations in there, but first I want to try with it as a basic just to see if it works.
Code Java:

```java.util.Scanner; public class budgetCalculator { public static void main(String[] args) { //Scanner Scanner scan = new Scanner(System.in); //Find out number of roommates. System.out.println("How many roommates do you have?:"); int occupancy = scan.nextInt(); //Find out rent. System.out.println("How much do you pay for rent? (in dollars):"); double rent = scan.nextInt(); //Find out car insurance. System.out.println("What do you pay for car insurance?:"); double carIns = scan.nextInt(); //Find out km driven per day. System.out.println("How many kilometres do you drive per day?:"); double kms = scan.nextInt(); //Find out mileage in car. System.out.println("What is the mileage on your car?:"); System.out.println("In case you aren't sure, an average is that:"); System.out.println("A very small car's mileage is 7.1L/100km"); System.out.println("A small car's mileage is 8.2L/100km."); System.out.println("A sport car's mileage is 14.9L/100km"); System.out.println("and an SUV's mileage is 12.3L/100km"); double fuelEfficiency = scan.nextInt(); //Find out average electric bill. System.out.println("What do you pay for electricity (every two months)?:"); double electricity = scan.nextInt(); // Find out average cable bill. System.out.println("What do you pay for cable each month?:"); double cable = scan.nextInt(); //Find out average water bill. System.out.println("What do you pay every 4 months for water?:"); double water = scan.nextInt(); //Find out average internet bill. System.out.println("What do you pay each month for Internet?:"); double internet = scan.nextInt(); //Find weekly food costs. System.out.println("What do you pay weekly for food?:"); double groceries = scan.nextInt(); //Find eating out cost. System.out.println("How much money do you spend eating out per week?:"); double resteraunt = scan.nextInt(); //Find out mweekly alcohol cost. System.out.println("How much do you spend on alcohol weekly?:"); double liquor = scan.nextInt();   System.out.println(determineTransportationCost(double kms, double fuelEfficiency, double carIns)); } public static double determineTransportationCost(double kms, double fuelEfficiency, double carIns) { double transportation = 30 * kms; return transportation; } }```

Help?
• October 1st, 2013, 10:38 PM
Junky
Re: Attempting to calculate a budget and using public static double method(...)
The compiler already knows what types your variables are in the method call. No need to include them.
• October 1st, 2013, 11:41 PM
taze
Re: Attempting to calculate a budget and using public static double method(...)
SO I did that and have been able to continue with my program, but now that it is mostly coded I have run into a problem. The program will not compile around the printReport method.

Code Java:

```import java.util.Scanner; public class budgetCalculator { public static void main(String[] args) { //Scanner Scanner scan = new Scanner(System.in); //Find out number of roommates. System.out.println("How many roommates do you have?:"); int occupancy = scan.nextInt(); occupancy = occupancy + 1; //Find out rent. System.out.println("How much do you pay for rent? (in dollars):"); double rent = scan.nextDouble(); //Find out car insurance. System.out.println("What do you pay for car insurance?:"); double carIns = scan.nextDouble(); //Find out km driven per day. System.out.println("How many kilometres do you drive per day?:"); double kms = scan.nextDouble(); //Find out mileage in car. System.out.println("What is the mileage on your car?:"); System.out.println("In case you aren't sure, an average is that:"); System.out.println("A very small car's mileage is 7.1L/100km"); System.out.println("A small car's mileage is 8.2L/100km."); System.out.println("A sport car's mileage is 14.9L/100km"); System.out.println("and an SUV's mileage is 12.3L/100km"); double fuelEfficiency = scan.nextDouble(); //Find out average electric bill. System.out.println("What do you pay for electricity (every two months)?:"); double electricity = scan.nextDouble(); // Find out average cable bill. System.out.println("What do you pay for cable each month?:"); double cable = scan.nextDouble(); //Find out average water bill. System.out.println("What do you pay every 4 months for water?:"); double water = scan.nextDouble(); //Find out average internet bill. System.out.println("What do you pay each month for Internet?:"); double internet = scan.nextDouble(); //Find weekly food costs. System.out.println("What do you pay weekly for food?:"); double groceries = scan.nextDouble(); //Find eating out cost. System.out.println("How much money do you spend eating out per week?:"); double resteraunt = scan.nextDouble(); //Find out mweekly alcohol cost. System.out.println("How much do you spend on alcohol weekly?:"); double liquor = scan.nextDouble();   printReport(budget, transportation, utility, food, housing); } public static double determineTransportationCost(double kms,double fuelEfficiency,double carIns) { double transportation = (30 * kms * (fuelEfficiency % 100)) * 1.32; return transportation; } public static double determineUtilityCost(double electricity, double cable, double water, double internet, int occupancy) { double utility = ((electricity % 2) + cable + (water % 4) + internet) % occupancy; return utility; } public static double determineFoodCost(double groceries, double restaurant, double liquor, int occupancy) { double food = ((groceries + restaurant + liquor) % occupancy) * 4; return food; } public static double determineHousingCost(double rent, int occupancy) { double housing = rent % occupancy; return housing; } public static double calculateTermBudget(double transportation, double utility, double food, double housing) double budget = transportation + utility + food + housing; return budget; } public static void printReport(double budget, double transportation, double utility, double food, double housing) { System.out.println("Your term budget is:" + budget); System.out.println("The break down is as follows:"); System.out.println((transportation % budget) * 100 + "%"); System.out.println((utility % budget) * 100 + "%"); System.out.println((food % budget) * 100 + "%"); System.out.println((housing % budget) * 100 + "%"); } }```
• October 1st, 2013, 11:44 PM
Junky
Re: Attempting to calculate a budget and using public static double method(...)
We don't read minds. Post the exact error message you get.
• October 2nd, 2013, 04:34 PM
taze
Re: Attempting to calculate a budget and using public static double method(...)
Code Java:

```import java.util.Scanner; public class budgetCalculator { public static void main(String[] args) { //Scanner Scanner scan = new Scanner(System.in); //Find out number of roommates. System.out.println("How many roommates do you have?:"); int occupancy = scan.nextInt(); occupancy = occupancy + 1; //Find out rent. System.out.println("How much do you pay for rent? (in dollars):"); double rent = scan.nextDouble(); //Find out car insurance. System.out.println("What do you pay for car insurance?:"); double carIns = scan.nextDouble(); //Find out km driven per day. System.out.println("How many kilometres do you drive per day?:"); double kms = scan.nextDouble(); //Find out mileage in car. System.out.println("What is the mileage on your car?:"); System.out.println("In case you aren't sure, an average is that:"); System.out.println("A very small car's mileage is 7.1L/100km"); System.out.println("A small car's mileage is 8.2L/100km."); System.out.println("A sport car's mileage is 14.9L/100km"); System.out.println("and an SUV's mileage is 12.3L/100km"); double fuelEfficiency = scan.nextDouble(); //Find out average electric bill. System.out.println("What do you pay for electricity (every two months)?:"); double electricity = scan.nextDouble(); // Find out average cable bill. System.out.println("What do you pay for cable each month?:"); double cable = scan.nextDouble(); //Find out average water bill. System.out.println("What do you pay every 4 months for water?:"); double water = scan.nextDouble(); //Find out average internet bill. System.out.println("What do you pay each month for Internet?:"); double internet = scan.nextDouble(); //Find weekly food costs. System.out.println("What do you pay weekly for food?:"); double groceries = scan.nextDouble(); //Find eating out cost. System.out.println("How much money do you spend eating out per week?:"); double resteraunt = scan.nextDouble(); //Find out mweekly alcohol cost. System.out.println("How much do you spend on alcohol weekly?:"); double liquor = scan.nextDouble();   printReport(budget, transportation, utility, food, housing); } public static double determineTransportationCost(double kms,double fuelEfficiency,double carIns) { double transportation = (30 * kms * (fuelEfficiency % 100)) * 1.32; return transportation; } public static double determineUtilityCost(double electricity, double cable, double water, double internet, int occupancy) { double utility = ((electricity % 2) + cable + (water % 4) + internet) % occupancy; return utility; } public static double determineFoodCost(double groceries, double restaurant, double liquor, int occupancy) { double food = ((groceries + restaurant + liquor) % occupancy) * 4; return food; } public static double determineHousingCost(double rent, int occupancy) { double housing = rent % occupancy; return housing; } public static double calculateTermBudget(double transportation, double utility, double food, double housing) { double budget = transportation + utility + food + housing; return budget; } public static void printReport(double budget, double transportation, double utility, double food, double housing) { System.out.println("Your term budget is:" + budget); System.out.println("The break down is as follows:"); System.out.println((transportation % budget) * 100 + "%"); System.out.println((utility % budget) * 100 + "%"); System.out.println((food % budget) * 100 + "%"); System.out.println((housing % budget) * 100 + "%"); } }```
It says that thee variables housing, food, utility, budget and transportation don't exist up in the printReport in the main method.
• October 2nd, 2013, 04:46 PM
GregBrannon
Re: Attempting to calculate a budget and using public static double method(...)
When someone says, "Post the exact error message you get," they mean copy the errors and stack trace you get when you run the code (show a sample run if possible), and paste what you've copied directly into a post. Use formatting tags if the error/stack trace is long and/or the formatting of the message is important.

Your filtered translation "It says that thee variables housing, food, utility, budget and transportation don't exist" is almost useless, because you don't really understand what you're reading. We'll help you understand the original, IF you show it to us.
• October 2nd, 2013, 05:50 PM
taze
Re: Attempting to calculate a budget and using public static double method(...)
oh, I see. The error after compiling is:
Code :

```budgetCalculator.java:49: error: cannot find symbol printReport(budget, transportation, utility, food, housing);   ^ symbol: variable budget location: class budgetCalculator budgetCalculator.java:49: error: cannot find symbol printReport(budget, transportation, utility, food, housing);   ^ symbol: variable transportation location: class budgetCalculator budgetCalculator.java:49: error: cannot find symbol printReport(budget, transportation, utility, food, housing);   ^ symbol: variable utility location: class budgetCalculator budgetCalculator.java:49: error: cannot find symbol printReport(budget, transportation, utility, food, housing);   ^ symbol: variable food location: class budgetCalculator budgetCalculator.java:49: error: cannot find symbol printReport(budget, transportation, utility, food, housing);   ^ symbol: variable housing location: class budgetCalculator 5 errors```
• October 2nd, 2013, 06:16 PM
GregBrannon
Re: Attempting to calculate a budget and using public static double method(...)
It's pointing at line 49. This forum doesn't show us line numbers, so posting code snippets usually requires pointing us to which posted line is being complained about. In this case, it's pretty easy to figure out which line is line 49. And then, it's pretty easy to see that you don't know how to use methods.

The method calculateTermBudget() returns a value which happens to be represented by a variable local to the method (not visible anywhere else) called 'budget'. So, the proper way to call print report is:

printReport( calculateTermBudget( transportation, utility, food, housing ), determineTransportationCost( kms, fuelEfficiency, carIns), etc. . . . )

That will result in new errors, because not all of the variables in those method calls have been defined, like transportation, utility, food, and housing. You'll have to rethink the design a bit. Should the calculateTermBudget() method be called first, or should the other methods be called first with their results used to call the calculateTermBudget() method?

I hope you can see the answer, because it's pretty clear.
• October 2nd, 2013, 08:17 PM
taze
Re: Attempting to calculate a budget and using public static double method(...)
Unfortunately - I don't see it clearly.

You state:
Should the calculateTermBudget() method be called first, or should the other methods be called first with their results used to call the calculateTermBudget() method?

I understand in what you mean by calling calculateTermBudget(....) first, like in your example, but I do not understand what you mean by calling the other methods first with their results used to call the termBudget method,

I've tried to rework the program from changing placement of the methods to trying different variations of printReport method (i.e. mainly rewriting what was above in different orders - it still will not recognize housing, transportation, utility and food (the error being that java cannot find the symbol).

So no, it really isn't as clear to me as one would expect.
• October 2nd, 2013, 10:37 PM
GregBrannon
Re: Attempting to calculate a budget and using public static double method(...)
Which of the following orders of operations will be successful:

1 -
c = a + b
a = 5
b = 8

2 -
a = 5
c = a + b
b = 8

3-
a = 5
b = 8
c = a + b
• October 3rd, 2013, 01:26 PM
taze
Re: Attempting to calculate a budget and using public static double method(...)
3. So basically, you're saying that what I am attempting to do is do a calculation without stating the variables first - trying to define c before I define a and b.

So I thought to, in place of my previous printReport statement, do this:

Code java:

```determineTransportationCost( kms,fuelEfficiency,carIns); determineUtilityCost(electricity,cable, water, internet,occupancy); determineFoodCost(groceries, restaurant, liquor, occupancy); determineHousingCost(rent,occupancy); calculateTermBudget(transportation,utility,food,housing); printReport(transportation,utility, food, housing, budget);```

The idea was that it would return my values so that calculateTermBudget could go through, however it still returns the same errors as above, so obviously I'm doing this wrong.
• October 3rd, 2013, 01:37 PM
GregBrannon
Re: Attempting to calculate a budget and using public static double method(...)
You're getting it, just not quite there yet. You're calling the methods, and the methods are returning values, but the program is not using the returned values. You can eliminate these variables by calling the methods directly in the printReport() method call, but you can also assign the returned values to variables before the method call, like this:

double foodCost = determineFoodCost(double groceries, double restaurant, double liquor, int occupancy);

Do the same for each of the variables that need to be defined before the method printReport() is called to present the results. Substitute those values, like foodCost, into the printReport() method call.
• October 3rd, 2013, 03:47 PM
taze
Re: Attempting to calculate a budget and using public static double method(...)
It compiles and with a few minor tweaks to the basic mathematics it works as it's supposed to! Thank you so much for the help and sorry for being so confused! You really cleared it up, thank you!
• October 3rd, 2013, 04:30 PM
GregBrannon
Re: Attempting to calculate a budget and using public static double method(...)
Glad to have helped and that you figured it out.
• October 4th, 2013, 07:40 PM
Mike1014
Re: Attempting to calculate a budget and using public static double method(...)
Quote:

Originally Posted by GregBrannon
Glad to have helped and that you figured it out.