Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ControllerChains {
- private int dollars;
- public ControllerChains(int dollars) { this.dollars = dollars; }
- public int getDollars() { return this.dollars; }
- public void setDollars(int dollars) { this.dollars = dollars; }
- public int getMaxPlayers() {
- int dollarsCopy = dollars;
- int availablePorts = 1;
- int controllers = 1;
- while (dollarsCopy >= 20) {
- if (availablePorts >= 1) {
- dollarsCopy -= 20;
- controllers++;
- availablePorts--;
- } else {
- dollarsCopy -= 12;
- availablePorts += 4;
- }
- }
- return controllers;
- }
- // Requires exactly one arg (int dollars) -- no error checking
- public static void main(String[] args) {
- ControllerChains controllerChains =
- new ControllerChains(Integer.parseInt(args[0]));
- System.out.println(controllerChains.getMaxPlayers());
- }
- }
Add Comment
Please, Sign In to add comment