5hassay

reddit.com/r/dailyprogrammer challenge #96 easy

Sep 6th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. public class ControllerChains {
  2.     private int dollars;
  3.  
  4.     public ControllerChains(int dollars) { this.dollars = dollars; }
  5.  
  6.     public int getDollars() { return this.dollars; }
  7.  
  8.     public void setDollars(int dollars) { this.dollars = dollars; }
  9.  
  10.     public int getMaxPlayers() {
  11.         int dollarsCopy = dollars;
  12.         int availablePorts = 1;
  13.         int controllers = 1;
  14.  
  15.         while (dollarsCopy >= 20) {
  16.             if (availablePorts >= 1) {
  17.                 dollarsCopy -= 20;
  18.                 controllers++;
  19.         availablePorts--;
  20.             } else {
  21.                 dollarsCopy -= 12;
  22.                 availablePorts += 4;
  23.             }
  24.         }
  25.  
  26.         return controllers;
  27.     }
  28.  
  29.     // Requires exactly one arg (int dollars) -- no error checking
  30.     public static void main(String[] args) {
  31.         ControllerChains controllerChains =
  32.             new ControllerChains(Integer.parseInt(args[0]));
  33.         System.out.println(controllerChains.getMaxPlayers());
  34.     }
  35. }
Add Comment
Please, Sign In to add comment