Advertisement
apad464

3rd FRQ #2

Apr 13th, 2023
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. class GameSpinner {
  2.     private int count = 0, last = 0, max = 0;
  3.  
  4.     public GameSpinner(int num) {
  5.         max = num;
  6.     }
  7.  
  8.     public int spin() {
  9.         int random = (int) (Math.random() * max) + 1;
  10.         if (random != last) count = 1;
  11.         else count++;
  12.         last = random;
  13.         return random;
  14.     }
  15.  
  16.     public int currentRun() {
  17.         return count;
  18.     }
  19. }
  20.  
  21. public class GameSpinnerRunner {
  22.     public static void main(String[] args) {
  23.         GameSpinner g = new GameSpinner(4);
  24.         System.out.println("run :: " + g.currentRun() + "\n");
  25.         for (int i = 1; i < 10; i++) {
  26.             System.out.println("spin :: " + g.spin());
  27.             System.out.println("run :: " + g.currentRun());
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement