# Using methods in methods ?

• 11-15-2011, 12:19 AM
jk91
Using methods in methods ?
Heey,

I would like to know where I'm screwing up in this piece of code. I had a lecture on working with methods today, so I tried to do some assignments.

I'm trying to call a method in a method, but this seems to be impossbile the way I do it.

The purpose of the code is to know find out who can serve more pizza's. Mario uses 3 ingredients on a pizza out of 10 available and Luigi 4 out of 9.

If anyone has got any other tips regarding my way of coding, feel free to shout it out loud :)

Here's what I wrote so far:

Code:

```package Pizza; import java.io.PrintStream; class Pizza {                 static final int NUMBERINGREDIENTSMARIO = 10;                 static final int NUMBERINGREDIENTSLUIGI = 9;                 static final int NUMBERCHOICESMARIO = 3;                 static final int NUMBERCHOICESLUIGI = 4;                 int a,b,c,d,h,i,j,x,y,options;                 PrintStream out;                                         Pizza() {                                 out = new PrintStream(System.out);                                                }                 // bereken de faculteit van een waarde                 void Factorial(int x) {                                        int factorialOfNumber = 1;                                 for (int p = 1; p <= x; p++) {                                         factorialOfNumber *= p;                                 }                                 out.printf("Factorial is %d",factorialOfNumber);                                 return;                         }                 // reken voor beide heren de formule uit m.b.v de input van de Factorialfunctie                 void Options(int numberIngredients, int numberChoices) {                                 h = Factorial(numberIngredients);                                 i = Factorial(numberChoices);                                 j = Factorial(numberIngredients - numberChoices);                                 int options = h / (i*j);                                 return options;                                 }                 // vergelijk de output van beide door options aan te roepen.                 void Compare(int a, int b, int c, int d) {                                 int x = Options(a,b);                                 int y = Options(c,d);                                 if(x > y) {                                                 out.print("Mario can serve more pizza's.");                                         } else {                                                 out.print("Luigi can serve more pizza's.");                                         }                         }                 void Start() {                                 Compare(NUMBERINGREDIENTSMARIO, NUMBERCHOICESMARIO, NUMBERINGREDIENTSLUIGI, NUMBERCHOICESLUIGI);                         }                         public static void main(String[] args) {                 new Pizza().Start();         } }```
• 11-15-2011, 12:25 AM
Junky
Re: Using methods in methods ?
Quote:

Originally Posted by jk91
I would like to know where I'm screwing up in this piece of code.

So would we. How about providing more details. If you get errors then post them.

Hint: A void method returns nothing.
• 11-15-2011, 12:38 AM
jk91
Re: Using methods in methods ?
Your hint did it! Thanks for your help. I changed the output of the methods and the program is working fine now.

Thanks again