techlinks.in
Low Level Design (LLD) Coding

Follow

Low Level Design (LLD) Coding

Follow
Design (LLD) a Jackpot machine - Machine Coding

Design (LLD) a Jackpot machine - Machine Coding

techlinks.in's photo
techlinks.in
·Feb 14, 2022·

2 min read

Play this article

Table of contents

  • Jackpot Machine
  • Features
  • Rough Solution (LLD-Machine Coding)

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) ;
        }
}

Did you find this article valuable?

Support techlinks.in by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this