Skip to content
Merged
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
46 changes: 46 additions & 0 deletions JV_Solutions/change_return.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class ChangeReturn

=begin
Author: Jessica Valenti
September 3, 2015
Change Return Program - user enters a cost and then the amount of money given. The program
will figure out the change and the number of quarters, dimes, nickels and pennies needed for the change.
=end

require 'bigdecimal' # used because Float and Integer data types aren't ideal for money transactions

puts "What is the cost?"
cost = BigDecimal(gets.chomp)

puts "What amount is given?"
moneyGiven = BigDecimal(gets.chomp)

while (cost > moneyGiven)
puts "The amount given must be greater than the cost. What amount is given?"
moneyGiven = BigDecimal(gets.chomp)
end

change = BigDecimal(moneyGiven) - BigDecimal(cost)
changeDollars = change.to_i
changeCents = (change - changeDollars)*100 # multiplied by 100 to use pennies

coin_values = {
"quarters" => 25,
"dimes" => 10,
"nickels" => 5,
"pennies" => 1
}

coinNames = ["quarters", "dimes", "nickels", "pennies"]
num = 0 # will be used to iterate through the names array above

puts "Your change is $" << sprintf('%.2f', change)

coin_values.each do |numCoins, value|
numCoins = changeCents / value
numCoins = numCoins.to_i # changed to integer to remove any decimal point on the num of coins
changeCents -= numCoins*value
puts "Number of #{coinNames[num]}: #{numCoins}" if numCoins > 0
num +=1 # to go to the next name in the array
end
end
22 changes: 22 additions & 0 deletions JV_Solutions/check_palindrome.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class CheckPalindrome
=begin
Author: Jessica Valenti
Date: September 2, 2015
Script that determines if a string is a palindrome or not.
=end

def checkPalindrome(word)
reversedWord = word.reverse
if (word == reversedWord)
puts "#{word} is a palindrome!"
else
puts "#{word} is not a palindrome :("
end
end

puts "Which string would you like to check?"
word = gets.chomp.downcase

palindromeObject = CheckPalindrome.new
palindromeObject.checkPalindrome(word)
end
30 changes: 30 additions & 0 deletions JV_Solutions/pigLatin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class PigLatin
=begin
Author : Jessica Valenti
September 1, 2015
Script created to "translate" English words into pig latin (based on the pig latin wikipedia page) - in response to Karan's list of projects
=end

puts "please write a word to be translated to pig latin"
word = gets.chomp
length = word.length

while length < 3
puts "please write a word to be translated to pig latin (longer than two letters)"
word = gets.chomp
length = word.length
end

vowels = ["a", "e", "i", "o", "u", "y"]

if vowels.include? word[0, 1]
pig_latin = word << "yay"
elsif vowels.include? word[1]
pig_latin = word[1, length] << word[0, 1] << "ay"
else
pig_latin = word[2, length] << word[0, 2] << "ay"
end

puts pig_latin

end