Giter Club home page Giter Club logo

year-11-unit-7-arraylists-tutorial-dominopile's Introduction

Year-11-Unit-7-ArrayLists-Tutorial-DominoPile

Part 1: Domino

Create a class to represent a single domino.

A domino consists of 2 sides, we'll call them "top" and "bottom". Each side holds an integer representing the number of dots it has.

Create the following functions:

  • Default Constructor - sets the top and bottom to 0.
  • Overloading Constructor - takes in 2 integers and puts the first one into top and the second one into bottom.
  • Getters
  • Setters
  • toString that displays the domino as a fraction (top/bottom) - Don't do actual math on this.
  • flip() - switches the order of the top and bottom values.
  • settle() - compares the top and bottom values and orders them so the smaller number is on top. (use flip to do this once the smaller value has been identified)
  • compareTo(Domino other)
    • Compares the smallest value of each domino.
      • If this < other - return -1
      • If this > other - return 1
      • If this == other Compare the larger value of each domino
        • If this < other - return -1
        • If this > other - return 1
        • If this == other - return 0
  • compareToWeight(Domino other)
    • Counts the total number of dots on each ½ of the Domino and compares it to the total number on the other domino.
      • Returns -1 if this < other
      • Returns 1 if this > other
      • Returns 0 if this == other
  • canConnect(Domino other)
    • Returns true if the 2 dominos have a common value on either side, otherwise it returns false. There are 4 possible ways of having a common value.
      • this.top → other.top
      • this.top → other.bottom
      • this.bottom → other.top
      • this.bottom → other.bottom

Part 2: DominoPile

This class contains 1 Instance variable: An ArrayList of Dominos called pile.

Implement the following Methods:

  • Default Constructor - Sets the pile to an empty arraylist of dominos.
  • newStack6() - puts in a complete set of dominoes from 0,0 to 6,6. Keep in mind that there are no repeated tiles (if there is already a 0,1, there can't be a 1,0). You must use a nested for-loop to solve this.
  • shuffle() - puts the dominos in a random order within the stack.
    • Option #1 - take all the values out of the original pile in a random order and add them to a new pile. Make the original pile equal to the new pile.
    • Option #2 - loop a large number of times simply grabbing 2 random tiles at a time and swapping their places.

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.