Loading...

12-Hour Money-Back Guarantee

Design (LLD) a Jackpot machine - Machine Coding

Design (LLD) a Jackpot machine - Machine Coding

Design (LLD) a Jackpot machine - Machine Coding

14 Feb 20224 min read

Text

Cakkpture.PNG

Jackpot Machine

  1. Total 3 slots

  2. Each slot have 0 -> 9 digits

  3. You get 10 chance

  4. Winner declaration 4.1 All three same 4.2 Times two same (449 994 885)

Features

  1. Start the game

  2. Trigger slot run - Pull the lever

  3. Keep track of outcomes -

  4. End game or declare winner whichever comes first

Rough Solution (LLD-Machine Coding)

Basic Entity

Player, Score, Slot , Random Number, JackPot Machine

Important Points

  1. There can be more than 3 slots also in a machine in future

  2. There can be multiple players who are using the same machine (may be turn by turn)

  3. Slots range may also change in future (so we should not hardcode them)

Final Code

Class JackpotMachine {
	Private:
		Int chance;
		Int totalSlots ;
		vector<Player> players ;
		vector<int> slotsRange ;
		map<player, winner> 
	Public
		JackpotMachine(int chance, int totalSlots, vector<int> slotRange) {
			
        }
       AddPlayer(Player p) {
       }
      pullTheLevel(player p) {
	
      }
 }
Class RandomNumber {
	Private:
		Int start;
		Int end ;
	public :
		RandomNumber(int start, int end) {
			
       }
      getRandomNumber() {
      }
 }

Class Slot : public RandomNumber {
	Public:
		Slot(int range) {
			RandomNumber(range) ;
        }
       getSlotValue() {
       }	
 }
Class Player {
	Private:
		Int playerId ;
		Int chances_left ;
		vector<Scores> playerScores ;
	Public :
		Player(int id, int chances) {
        }
       pullTheLever() {
	       if(chances_left == 0) return “You LOSE” ;
	       Chances_lef– ;
       }
      getScore() {
	       Return playerScores ;
      }
}
Class Scores {
	Private:
		vector<int> score;
	Public:
		Scores(int totalSlots) {	
			score.reszie(totalSlots) ;
        }
}

Better and Complete Working Code (in IDE)(Java) - https://code.lldcoding.com/ide/jackpot-machine


Issues in Above Design and Code

🔥 Problem 1: Slot Generation Is NOT Deterministic or Testable

❌ What we Did

Class Slot : public RandomNumber

❌ What’s Wrong

  • Slot inherits randomness

  • Game logic depends on random outcomes

  • Impossible to:

    • Write unit tests

    • Replay a game

    • Debug production issues

💣 Interviewer Trap:

“How would you test win conditions deterministically?”

Most candidates freeze here.

Solution