Guest User

Untitled

a guest
Feb 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.75 KB | None | 0 0
  1.     public void act(int whichStock, Action action, int amount) {
  2.         Stock stock01 = stock1;
  3.         Stock stock02 = stock2;
  4.         Stock stock03 = stock3;
  5.         //test if should be 2 or 3
  6.         if (isStarted() == true) {
  7.             switch (action) {
  8.                 case UP:
  9.                     //handle a stock split
  10.                     if (stock01.getValue() + amount >= 200) {
  11.                         player.setHolding1(player.getHolding1() * 2);
  12.                         stock01.setValue(100);
  13.                         log("SPLIT: Set player " + player.getName() + "'s " + stock01.getName() + " to " + player.getHolding1() + " and reset stock to 100");
  14.                     } else if (stock02.getValue() + amount >= 200) {
  15.                         player.setHolding2(player.getHolding2() * 2);
  16.                         stock02.setValue(100);
  17.                         log("SPLIT: Set player " + player.getName() + "'s " + stock02.getName() + " to " + player.getHolding2() + " and reset stock to 100");
  18.                     } else if (stock03.getValue() + amount >= 200) {
  19.                         player.setHolding3(player.getHolding3() * 2);
  20.                         stock03.setValue(100);
  21.                         log("SPLIT: Set player " + player.getName() + "'s " + stock03.getName() + " to " + player.getHolding3() + " and reset stock to 100");
  22.                     } else {
  23.                         //handle a stock increase
  24.                         switch (whichStock) {
  25.                             case 1:
  26.                                 stock01.setValue(stock01.getValue() + amount);
  27.                                 log("Increased " + stock01.getName() + " by " + amount);
  28.                                 break;
  29.                             case 2:
  30.                                 stock02.setValue(stock02.getValue() + amount);
  31.                                 log("Increased " + stock02.getName() + " by " + amount);
  32.                                 break;
  33.                             case 3:
  34.                                 stock03.setValue(stock03.getValue() + amount);
  35.                                 log("Increased " + stock03.getName() + " by " + amount);
  36.                                 break;
  37.                         }
  38.                     }
  39.                     break;
  40.                 case DOWN:
  41.                     //handle a stock delist
  42.                     if (stock01.getValue() - amount <= 0) {
  43.                         player.setHolding1(0);
  44.                         stock01.setValue(100);
  45.                         log("DELIST: Set player " + player.getName() + "'s " + stock01.getName() + " to " + player.getHolding1() + " and reset stock to 100");
  46.                     } else if (stock02.getValue() - amount <= 0) {
  47.                         player.setHolding2(0);
  48.                         stock02.setValue(100);
  49.                         log("DELIST: Set player " + player.getName() + "'s " + stock02.getName() + " to " + player.getHolding2() + " and reset stock to 100");
  50.                     } else if (stock03.getValue() - amount <= 0) {
  51.                         player.setHolding3(0);
  52.                         stock03.setValue(100);
  53.                         log("DELIST: Set player " + player.getName() + "'s " + stock03.getName() + " to " + player.getHolding3() + " and reset stock to 100");
  54.                     } else {
  55.                         switch (whichStock) {
  56.                             case 1:
  57.                                 stock01.setValue(stock01.getValue() - amount);
  58.                                 log("Decreased " + stock01.getName() + " by " + amount);
  59.                                 break;
  60.                             case 2:
  61.                                 stock02.setValue(stock02.getValue() - amount);
  62.                                 log("Decreased " + stock01.getName() + " by " + amount);
  63.                                 break;
  64.                             case 3:
  65.                                 stock03.setValue(stock03.getValue() - amount);
  66.                                 log("Decreased " + stock01.getName() + " by " + amount);
  67.                                 break;
  68.                         }
  69.                     }
  70.                     break;
  71.                 case DIV:
  72.                     switch (whichStock) {
  73.                         case 1:
  74.                             if (stock01.getValue() >= 100) {
  75.                                 player.setCash(player.getCash() + (player.getHolding1() * amount));
  76.                                 log("Payed dividend of " + (player.getHolding1() * amount) + " to stock " + stock01.getName());
  77.                                 break;
  78.                             } else {
  79.                                 break;
  80.                             }
  81.                         case 2:
  82.                             if (stock02.getValue() >= 100) {
  83.                                 player.setCash(player.getCash() + (player.getHolding2() * amount));
  84.                                 log("Payed dividend of " + (player.getHolding2() * amount) + " to stock " + stock02.getName());
  85.                                 break;
  86.                             } else {
  87.                                 break;
  88.                             }
  89.                         case 3:
  90.                             if (stock03.getValue() >= 100) {
  91.                                 player.setCash(player.getCash() + (player.getHolding3() * amount));
  92.                                 log("Payed dividend of " + (player.getHolding3() * amount) + " to stock " + stock03.getName());
  93.                                 break;
  94.                             } else {
  95.                                 break;
  96.                             }
  97.                     }
  98.                     break;
  99.             }
  100.         } else if (isOver() == true) {
  101.             return;
  102.         }
  103.     }
Add Comment
Please, Sign In to add comment