Coder Social home page Coder Social logo

checkpoint-04's Introduction

Checkpoint 04

If you have not completed the survey yet, please do so by the end of the day!

Instructions

  1. Fork this repo
  2. Clone your fork
  3. Fill in your answers by writing in the appropriate area, or placing an 'x' in the square brackets (for multiple-choice questions).
  4. Add/Commit/Push your changes to Github.
  5. Open a pull request.

Note: Only place your answer between backticks. Don't modify the backticks, or the language specifier after them.

Ruby Basics & Enumerables (meets Beauty and the Beast)

Question 1

Define a method called offer_rose, which should take one argument named person.

When called the method should puts "Would you take this rose, person, in exchange for giving an old beggar woman shelter from the bitter cold?"

Demonstrate calling the method, passing in "young prince" as the argument.

Write your code here:

def offer_rose person
  puts "Would you take this rose, #{person}, in exchange for giving an old beggar woman shelter from the bitter cold?"
end

offer_rose "young prince"

Question 2

Assume the following hash:

town = {
  residents: ["Maurice", "Belle", "Gaston"],
  castle: {
    num_rooms: 47,
    residents: "Robby Benson",
    guests: []
  }
}

Using Ruby, remove Belle from the town residents, and add her to the list of guests in the castle.

Write your code here:

town[:castle][:guests] << town[:residents].slice!(1)

Question 3

Assume you have an array of strings representing friend's names:

friends = ["Chip Potts", "Cogsworth", "Lumière", "Mrs. Potts"]

Using .each AND string interpolation, produce output (using puts) like so:

Belle is friends with Chip Potts
Belle is friends with Cogsworth
Belle is friends with Lumière
Belle is friends with Mrs. Potts

Write your code here:

friends.each do |friend|
  puts "Belle is friends with #{friend}"
end

Ruby OOP (meets Lion King)

Question 4

Create ruby classes for Animal and Lion. Each Animal should have:

  • a name attribute
  • a greet instance method
  • Getter and setter for name

Create a new Animal instance with the name "Pumba"

Make the Lion inherit from the Animal class. The Lion class should have a pack class variable that holds references to each instance created.

Each lion should have:

  • a king attribute which is a boolean
    • If the instance's name is Simba make the king attribute true

Create a new lion instance with the name simba

class Animal
  attr_accessor :name
  def initialize name
    @name = name
  end
  def greet
    puts "Hi there! I'm #{@name}"
  end
  def get_name
    return @name
  end
  def set_name string
    @name = string
  end
end
Pumba = Animal.new "Pumba"
Pumba.greet

class Lion < Animal
  attr_accessor :name, :king
  @@pack = []
  def initialize name
    super name
    @@pack << self
    @king = false
    if @name == "Simba"
      @king = true
    end
  end
end
Simba = Lion.new "Simba"
puts Simba.inspect

SQL, Databases, and ActiveRecord (meets Aladdin)

Question 5

Describe what an ERD is, and why we create them for applications. Also give an example what the attributes and relationships might be for the following entities (no need to draw an ERD):

  • Genie
  • Lamp
  • Person
  • Pet

Your answer:

An ERD is an Entity Relationship Diagram, which is a fancy term for a visualization of the relationships between different entities in our data, e.g. classes.  Though it is useful in other circumstances than code, in this class, it will be used most to clarify how and when to institute a new class or a new instance.

A genie, who might have attributes such as name, age, and array of wishes granted, will have a one to one relationship with its lamp.  The genie will have a many to many relationship with a person, who will probably have a wishes left attribute.  Pets will also be a many to many relationships, and might have an attribute type, which could be carpet or monkey.

Question 6

Describe what a schema is, and how we represent a one-to-many relationship in a SQL database. If you need an example, you can use: people and wishes (one-to-many).

Your answer:

The schema is what controls the columns on the table, and organizes our data, along with their types and any constraints.  With the wishes example, each wish would have a foreign key linking it to its person, and their would be a constraint on the number of wishes for each person.

checkpoint-04's People

Contributors

lizafloyd avatar nolds9 avatar

Watchers

James Cloos avatar

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.