Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package methodsAndFunctions;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Scanner;
  5.  
  6. class Pizza {
  7.     // Name         :   Christopher Esterhuyse
  8.     // Assignment   :   methodsAndFunctions
  9.     // Date         :   16-September 2014
  10.    
  11.     PrintStream out;
  12.    
  13.     Pizza() {
  14.         out = new PrintStream(System.out);
  15.     }
  16.    
  17.     void start() {
  18.         Scanner in = new Scanner(System.in);
  19.         int MARIO_POSSIBLE = 10,
  20.             MARIO_NUMBER = 3,
  21.             LUIGI_POSSIBLE = 9,
  22.             LUIGI_NUMBER = 4;
  23.        
  24.         if(possibilities(MARIO_POSSIBLE, MARIO_NUMBER) > possibilities(LUIGI_POSSIBLE, LUIGI_NUMBER)){
  25.             out.printf("Mario wins the bet!");
  26.         }else{
  27.             if(possibilities(MARIO_POSSIBLE, MARIO_NUMBER) < possibilities(LUIGI_POSSIBLE, LUIGI_NUMBER)){
  28.             out.printf("Luigi wins the bet!");
  29.         }else{
  30.             out.printf("Both brothers are tied!");
  31.             }
  32.         }
  33.         in.close();
  34.     }
  35.        
  36.     int possibilities(int possibleToppings, int numberToppings){
  37.         int result = factorial(possibleToppings)/(factorial(numberToppings)*factorial(possibleToppings-numberToppings));    //n!/(k!(n-k)!)
  38.         return result;
  39.     }
  40.    
  41.     int factorial(int n){
  42.         int result = 1;
  43.         for(int i=1; i<n; i++){
  44.             result *= i;
  45.         }
  46.         return result;
  47.     }
  48.    
  49.     public static void main (String[] argv) {
  50.         new Pizza().start();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement