Code Monkey home page Code Monkey logo

practice-relationships-jackpot's Introduction

Object Relations Code Challenge - JackPot

For this challenge, we'll be working with a JackPot domain.

We have three models: Bid, Gambler, and Dealer.

A Gambler has many Bidss. A Dealer has many Bidss. A Bid belongs to a Gambler and belongs to a Dealer.

Gambler - Dealer is a many to many relationship.

Note: You should draw your domain on paper or on a whiteboard before you start coding. Remember to identify a single source of truth for your data.

Topics

  • Classes and Instances
  • Class and Instance Methods
  • Variable Scope
  • Object Relationships
  • lists and list Methods

Instructions

To get started, run pipenv install while inside of this directory.

Build out all of the methods listed in the deliverables. The methods are listed in a suggested order, but you can feel free to tackle the ones you think are easiest. Be careful: some of the later methods rely on earlier ones.

Remember! This code challenge does not have tests. You cannot run pytest. You'll need to create your own sample instances so that you can try out your code on your own. Make sure your relationships and methods work in the console before submitting.

We've provided you with a tool that you can use to test your code. To use it, run python tools/debug.py from the command line. This will start a ipdb session with your classes defined. You can test out the methods that you write here. You can add code to the tools/debug.py file to define variables and create sample instances of your objects.

Writing error-free code is more important than completing all of the deliverables listed - prioritize writing methods that work over writing more methods that don't work. You should test your code in the console as you write.

Similarly, messy code that works is better than clean code that doesn't. First, prioritize getting things working. Then, if there is time at the end, refactor your code to adhere to best practices. When you encounter duplicated logic, extract it into a shared helper method.

Before you submit! Save and run your code to verify that it works as you expect. If you have any methods that are not working yet, feel free to leave comments describing your progress.

Deliverables

Write the following methods in the classes in the files provided. Feel free to build out any helper methods if needed.

Initializers, Readers, and Writers

Gambler

  • Gambler __init__(self, name)
    • Gambler is initialized with a name (string)
  • Gambler get_name()
    • returns the Gambler's name

Dealer

  • Dealer __init__(self, name)
    • Dealer is initialized with a name (string)
  • Dealer get_name()
    • returns the Dealer's name

Bid

  • Bid __init__(self, gambler, dealer, amount)
    • Bid is initialized with a Gambler instance, a Dealer instance, and an amount (float)
  • Bid get_amount()
    • returns the amount for the Bid instance

Object Relationship Methods

Bid

  • Bid get_gambler()
    • returns the Gambler instance associated with the Bid instance
  • Bid get_dealer()
    • returns the Dealer instance associated with the Bid instance

Gambler

  • Gambler get_bids()
    • returns a list of Bid instances associated with the Gambler instance.
  • Gambler get_dealers()
    • returns a list of Dealer instances who made a bid with the Gambler instance.
    • HINT: you can get the dealers by iterating through the list of bids

Dealer

  • Dealer get_bids()
    • returns a list of all the Bid instances for the Dealer.
  • Dealer get_gamblers()
    • returns a list of all of the Gambler instances that made a bid with the Dealer.
    • HINT: you can get the gamblers by iterating through the list of bids

Aggregate and Association Methods

Gambler

  • Gambler has_bidded(dealer)

    • returns True if the Gambler has made a bid with this Movie (if there is a Bid instance for this Gambler that exists with the Dealer), returns False otherwise
  • Gambler make_bid(dealer, amount)

    • a Dealer instance and an amount (float) are passed in as arguments
    • this method should create a new Bid instance and attach it to both the Gambler instance and the Dealer instance
  • Gambler average_bid_amount()

    • returns the average of all bid amounts for the Gambler instance
    • to average bid amounts, add all bid amounts together and divide by the total number of bids.
  • Gambler highest_bid()

    • returns the Bid instance with the highest bid amount for the gambler.

    BONUS

    • Gambler highest_average_gambler()
      • returns the gambler with the highest average bids.

practice-relationships-jackpot

practice-relationships-jackpot's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.