Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 02_Variables_Conditionals/starter_code/Sec 6 of rubby book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
puts 'Hello player! Welcome to Marija\'s Magnificant Test of Psychic Abilities game! You will have 3 attempts to guess a number, 1 through 10. What is your name?'
name = gets.chomp
puts 'Hello, ' + name.capitalize + '!'

puts 'Let us begin! I am thinking of a number between 1 and 10, please guess what number this is!'

number = (rand(1..10))
guess = gets.to_i
attempts = 3

if guess == number
puts 'You are correct, the number is ' + number.to_s + '!'
elsif guess < number
puts "Wrong, aim higher and please try again!"
elsif guess > number
puts "Wrong, aim lower and please try again!"
end
end



29 changes: 29 additions & 0 deletions 02_Variables_Conditionals/starter_code/SecNumHW.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Marija Ringwelski Homework Assignment answers:

puts 'Hello player! Welcome to Marija\'s Magnificant Test of Psychic Abilities game! What is your name?'
name = gets.chomp.capitalize # .capitalize will make the first letter of the name capitalized.
puts 'Hello, ' + name + '!'
puts 'Let us begin! You get 3 guesses. I am thinking of a number between 1 and 10, please guess what number this is!'

number = (rand(1..10)) # rand(1..10) will privide a range between 1 and 10. rand(10) might include zero and we dont want that.
guess_remainder = 3 # this prompt will allow for the number of attempts the respondent can make.

loop do # this command will allow for repeated actions of the program for guess_remainder number indicated.
guess = gets.to_i # .to_1 method will allow for the conversion of the guess into an integer
guess_remainder -= 1 # -= 1 will allow the program to subtract by one guess after each response.
if guess == number
puts 'You are correct, the number is ' + number.to_s + '!'
break
elsif guess != number and guess_remainder != 0
if guess < number
puts "Wrong, aim higher and please try again! Number of attempts left: " + guess_remainder.to_s + '.' # .to_s will return a string for guess_remainder.
elsif guess > number
puts "Wrong, aim lower and please try again! Number of attempts left: " + guess_remainder.to_s + '.' # .to_s will return a string for guess_remainder.
end
else puts "Sorry, you lost and have zero psychic abilities! The number was " + number.to_s + '.' # .to_s will return a string for guess_remainder.
break
end
end



38 changes: 38 additions & 0 deletions 02_Variables_Conditionals/starter_code/SecNumHWv2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Marija Ringwelski Homework Assignment answers:

puts 'Hello player! Welcome to Marija\'s Magnificant Test of Psychic Abilities game! What is your name?'
name = gets.chomp.capitalize # .capitalize will make the first letter of the name capitalized.
puts 'Hello, ' + name + '!'
puts 'Let us begin! You get 3 guesses. I am thinking of a number between 1 and 10, please guess what number this is!'
guess = gets.to_i # .to_1 method will allow for the conversion of the guess into an integer

number = (rand(1..10))
# number = (rand(1..10)) # rand(1..10) will privide a range between 1 and 10. rand(10) might include zero and we dont want that.
guess_remainder = 3 # this prompt will allow for the number of attempts the respondent can make.

# this command will allow for repeated actions of the program for guess_remainder number indicated.
while guess_remainder > 0

if guess < number
# .to_s will return a string for guess_remainder.
puts "Wrong, aim higher and please try again! Number of attempts left: " + guess_remainder.to_s + '.'
guess = gets.to_i
elsif guess > number
# .to_s will return a string for guess_remainder.
puts "Wrong, aim lower and please try again! Number of attempts left: " + guess_remainder.to_s + '.'
guess = gets.to_i
end
guess_remainder -= 1 # -= 1 will allow the program to subtract by one guess after each response.

end

if guess == number
puts 'You are correct, the number is ' + number.to_s + '!'

else
# .to_s will return a string for guess_remainder.
puts "Sorry, you lost and have zero psychic abilities! The number was " + number.to_s + '.'
end



37 changes: 37 additions & 0 deletions 02_Variables_Conditionals/starter_code/calc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
puts 1+2
puts 3*4
puts (24*365)
puts (60*24)*(365*10)
puts (60*60*24)*(365*30)

my_string = "say my name"
puts my_string
puts my_string

name = "Marija Ringwelski"
puts "My name is " + name + '.'
var1 = 2
var2 = '5'
puts var1.to_s + var2
puts var1 + var2.to_i

puts 'Hello there, and what\'s your name?'
name = gets.chomp
puts 'Your name is ' + name + '? What a lovely name!'
puts 'Pleased to meet you, ' + name + '. :)'

puts 'Hello there, what\'s your first name?'
first_name = gets.chomp
puts 'What is your middle name?'
middle_name = gets.chomp
puts 'What is your last name?'
last_name = gets.chomp
puts 'Pleased to meet you, ' + first_name + ' ' + middle_name + ' ' + last_name + '!'


puts 'What is your fav number?'
fav_number = gets.chomp.to_i
bet_number = fav_number + 1
puts "that is okay, but is not " +bet_number.to_s+ ' bigger and better?'


2 changes: 2 additions & 0 deletions 02_Variables_Conditionals/starter_code/class 05272014.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


39 changes: 39 additions & 0 deletions 02_Variables_Conditionals/starter_code/code_demo_boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,54 @@
#Let the computer do the work for you!

puts "Is 7 greater than 8?"
if 7 > 8
puts true
else
puts false
end

puts "Is 8 x 77 greater than 600?"
if (8 * 77) > 600
puts true
else
puts false
end


puts "Is 1 equal to (7 - 6)?"

if 1 == (7-6)
puts true
else
puts false
end


puts "Is 77 greater than 50 AND (88 / 3) less than 30?"
if 77 > 50 and (88/3)<30
puts true
else
puts false
end


puts "Is the length of the word 'wheelbarrow' more than 10 characters long?"
if "wheelbarrow".length > 10
puts true
else
puts false
end

puts "Are the amount of seconds in an hour greater than or equal to 3000?"
if (60 ==3000) or > 3000
puts true
else
puts false
end

puts "Does the word 'slaughter' include the word laughter?"
if "slaughter".include? "laughter"
puts true
else
puts false
end
35 changes: 35 additions & 0 deletions 02_Variables_Conditionals/starter_code/ex_teddit_conditionalv2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Teddit Contionals - Starter Code.

# Let's add a new Teddit feature. Upvotes!
# Complete the application below.
# Where you see comments (lines that begin with #) replace it with code so that the program works.

def get_input
gets
end

def calculate_upvotes(story, category)
upvotes = 1
if story.include? "cats" or category.include? "cats"
upvotes.to_i*5
elsif story.include? "bacon" or category.include? "bacon"
upvotes.to_i*8
elsif story.include? "Food" or category.include? "Food"
upvotes.to_1*3
end


# If the Story is about cats multiply the upvotes by 5
# If the Story is about bacon multiply the upvotes by 8
# If the Story is about Food it gets 3 times the upvotes.
#For example:
# "Cats frolic despite tuna shortage" should give you 5 times the upvotes!
end

puts "Welcome to Teddit! a text based news aggregator. Get today's news tomorrow!"
puts "Please enter a News story:"
story = get_input
puts "Please give it a category:"
category = get_input
upvotes = calculate_upvotes(story, category)
puts "New story added! #{story}, Category: #{category.capitalize}, Current Upvotes: #{upvotes}"
1 change: 1 addition & 0 deletions 02_Variables_Conditionals/starter_code/ruby calc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts 1+2
Empty file.
19 changes: 19 additions & 0 deletions 05_Classes_Objects/starter_code/ex_apartment_objects/Apt_code.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#This is the apartment code for lab exercise on 06022014

def create_apartment
puts "This is a new apartment."
puts "What is the apartment number / name?"
name = gets.strip

puts "How many square feet is apartment #{name}?"
apt_sqft = gets.to_i

puts "How many bedrooms does apartment #{name} have?"
apt_bedrooms = gets.to_i

puts "How many bathrooms does apartment #{name} have?"
apt_bathrooms = gets.to_i

Apartment.new(name, apt_sqft, apt_bedrooms, apt_bathrooms)
end

12 changes: 12 additions & 0 deletions 05_Classes_Objects/starter_code/ex_apartment_objects/Bldg_code.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#This is the building code for lab exercise on 06022014

def create_building
puts "This is a new building."
puts "What is the building's name?"
building_name = gets.strip

puts "What is the building's address?"
building_address = gets.strip

Building.new(building_name, building_address)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#This is the renter's code for lab exercise on 06022014

def create_renter
puts "There is a new renter"
puts "What is the renter's name?"
name = gets.strip

puts "What is the #{name}'s credit score?"
credit_score = gets.to_i

puts "Is #{name} male or female?"
gender = gets.strip

Person.new(name, credit_score, gender)
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#the object is
#player object
#sec num object

random - method used

class - instead of ifs and else, create methods for the check work

user class
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#Apartment class.
class Apartment
attr_accessor :name, :apt_sqft, :apt_bedrooms, :apt_bathrooms, :renter, :rent

def initialize(name, apt_sqft, apt_bedrooms, apt_bathrooms)
@name = name
@apt_sqft = apt_sqft
@apt_bedrooms = apt_bedrooms
@apt_bathrooms = apt_bathrooms
@renter = nil
@rent = nil
end
end

# apartment


Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#Building Class
class Building
attr_accessor :building_name, :building_address, :apartments

def initialize(building_name, building_address)
@building_name = building_name
@building_address = building_address
@apartments = []
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#Person Class.
class Person
attr_accessor :name, :credit_score, :gender

def initialize(name, credit_score, gender)
@name = name
@credit_score = credit_score
@gender = gender
end
end
6 changes: 3 additions & 3 deletions 05_Classes_Objects/starter_code/ex_apartment_objects/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# => We've also provided a png file of the terminal output from the completed version.
# => Hint: Think before you code. Annotate code and comment out sections as you test different sections

require_relative 'lib/building'
require_relative 'lib/apartment'
require_relative 'lib/person'
require_relative 'lib/building' #create a separate file
require_relative 'lib/apartment' #create a separate file
require_relative 'lib/person' #create a separate file

## First, define our methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,47 @@
require 'lib/secret_number'

class Game
# this class will be complex
# we need to write logic to initialize a new game, and run the game loop
# we'll want to write a few separate methods for unique tasks so that our
# code is structured properly
def initialize(player, sec_num)
@player = player
@sec_num = sec_num
end

player = Person.new(name)
sec_num = SecretNumber.new

game = Game.new(player, secret_number)

end

number = (rand(1..10))
guess_remainder = 3

while guess_remainder > 0

if guess < secret_number
puts "Wrong, aim higher and please try again! Number of attempts left: " + guess_remainder.to_s + '.'
guess = gets.to_i

elsif guess > secret_number

puts "Wrong, aim lower and please try again! Number of attempts left: " + guess_remainder.to_s + '.'
guess = gets.to_i
end
guess_remainder -= 1

end

if guess == number
puts 'You are correct, the number is ' + number.to_s + '!'
else
puts "Sorry, you lost and have zero psychic abilities! The number was " + number.to_s + '.'
end

#Game
# This class holds most of the game logic and should:
# Welcome players and inform them of the game rules.
# Initialize the Player class.
# Initialize the Secret Number class.
# Prompt the user to choose a number, verify if the user guessed correctly.
# If the user guesses incorrectly let them know if they were too high or too low.
# Monitor how many guesses the player has before the game is over.
Loading