From daacde74c989f506167d0f0ebae77408ce60807d Mon Sep 17 00:00:00 2001 From: pinkninjajess Date: Tue, 1 Sep 2015 18:41:39 -0400 Subject: [PATCH 1/6] PigLatin Solution Author: Jessica Valenti --- JV_Solutions/pigLatin.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 JV_Solutions/pigLatin.rb diff --git a/JV_Solutions/pigLatin.rb b/JV_Solutions/pigLatin.rb new file mode 100644 index 000000000..b53dc8328 --- /dev/null +++ b/JV_Solutions/pigLatin.rb @@ -0,0 +1,31 @@ +class PigLatin +=begin +end + 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 \ No newline at end of file From 1f22aea841ce600f487cfb9089cedba57806c060 Mon Sep 17 00:00:00 2001 From: pinkninjajess Date: Tue, 1 Sep 2015 18:50:12 -0400 Subject: [PATCH 2/6] Minor edit --- JV_Solutions/pigLatin.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/JV_Solutions/pigLatin.rb b/JV_Solutions/pigLatin.rb index b53dc8328..0c5861865 100644 --- a/JV_Solutions/pigLatin.rb +++ b/JV_Solutions/pigLatin.rb @@ -1,6 +1,5 @@ class PigLatin =begin -end 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 From 38c158044217100fe8e1ae10b48ad751ae72dba3 Mon Sep 17 00:00:00 2001 From: pinkninjajess Date: Wed, 2 Sep 2015 21:09:22 -0400 Subject: [PATCH 3/6] Pig Latin Solution --- JV_Solutions/check_palindrome.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 JV_Solutions/check_palindrome.rb diff --git a/JV_Solutions/check_palindrome.rb b/JV_Solutions/check_palindrome.rb new file mode 100644 index 000000000..7693f45c9 --- /dev/null +++ b/JV_Solutions/check_palindrome.rb @@ -0,0 +1,23 @@ +class CheckPalindrome +=begin +Author: Jessica Valenti +Date: September 2, 2015 + +Script that determines whether a string is a palindrome. +=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 \ No newline at end of file From 7f9df768cc6f8283ea5ddb4dc867fd63753f101e Mon Sep 17 00:00:00 2001 From: Jessica Valenti Date: Wed, 2 Sep 2015 21:22:01 -0400 Subject: [PATCH 4/6] Delete check_palindrome.rb --- JV_Solutions/check_palindrome.rb | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 JV_Solutions/check_palindrome.rb diff --git a/JV_Solutions/check_palindrome.rb b/JV_Solutions/check_palindrome.rb deleted file mode 100644 index 7693f45c9..000000000 --- a/JV_Solutions/check_palindrome.rb +++ /dev/null @@ -1,23 +0,0 @@ -class CheckPalindrome -=begin -Author: Jessica Valenti -Date: September 2, 2015 - -Script that determines whether a string is a palindrome. -=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 \ No newline at end of file From eb3f0681bfef4b471848c2f82d60a57e8427dae4 Mon Sep 17 00:00:00 2001 From: pinkninjajess Date: Wed, 2 Sep 2015 21:26:16 -0400 Subject: [PATCH 5/6] Check Palindrome Ruby Solution --- JV_Solutions/check_palindrome.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 JV_Solutions/check_palindrome.rb diff --git a/JV_Solutions/check_palindrome.rb b/JV_Solutions/check_palindrome.rb new file mode 100644 index 000000000..00d5c0da5 --- /dev/null +++ b/JV_Solutions/check_palindrome.rb @@ -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 \ No newline at end of file From 4f74d27294a4501f7659df6bfbc3eabce5317454 Mon Sep 17 00:00:00 2001 From: pinkninjajess Date: Thu, 3 Sep 2015 15:29:48 -0400 Subject: [PATCH 6/6] My Change Return Ruby Solution --- JV_Solutions/change_return.rb | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 JV_Solutions/change_return.rb diff --git a/JV_Solutions/change_return.rb b/JV_Solutions/change_return.rb new file mode 100644 index 000000000..688903a8f --- /dev/null +++ b/JV_Solutions/change_return.rb @@ -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 \ No newline at end of file