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 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 diff --git a/JV_Solutions/pigLatin.rb b/JV_Solutions/pigLatin.rb new file mode 100644 index 000000000..0c5861865 --- /dev/null +++ b/JV_Solutions/pigLatin.rb @@ -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 \ No newline at end of file