Results 1 to 3 of 3
  1. #1
    jk91 is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default 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:

    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();
    
    	}
    
    }
    Thanks in advance !

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Using methods in methods ?

    Quote Originally Posted by jk91 View Post
    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.

  3. #3
    jk91 is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default 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

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Replies: 1
    Last Post: 10-23-2011, 12:37 PM
  3. Replies: 1
    Last Post: 10-05-2011, 12:15 AM
  4. Methods Please help
    By bdario1 in forum New To Java
    Replies: 33
    Last Post: 03-25-2010, 03:26 AM
  5. Replies: 4
    Last Post: 04-03-2009, 06:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •