Results 1 to 3 of 3
Thread: Using methods in methods ?
- 11-14-2011, 11:19 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
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:
Thanks in advance !Java 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-14-2011, 11:25 PM #2
- 11-14-2011, 11:38 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
difference between static methods and instantce methods?
By venkatch in forum New To JavaReplies: 1Last Post: 10-23-2011, 12:37 PM -
Incorporating If-Else into Methods + Private Helper Methods?
By 5minutes in forum New To JavaReplies: 1Last Post: 10-05-2011, 12:15 AM -
Methods Please help
By bdario1 in forum New To JavaReplies: 33Last Post: 03-25-2010, 03:26 AM -
How to get methods to see variables in other methods
By ejs7597 in forum New To JavaReplies: 4Last Post: 04-03-2009, 06:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks