multiverse-team-11 / inventory-app

https://inventory-app-11-1emn.onrender.com/
0 stars 2 forks source link

Arrays & Hashes - Build Something 🔨 #78

Closed Hannah0701 closed 4 weeks ago

Hannah0701 commented 1 month ago

Option #1 - Word Frequency Analyzer: Create a word frequency analyzer that reads a string, process its contents, and generate a report of the frequency of each word in the file. Be sure to utilize arrays, hashes, and iteration. Option #2 - Movie Recommendation System: Create a movie recommendation system that will suggest movies to users based on their preferences and previously watched movies. The program should read a array and/or hash containing a list of previously watched movies and their genres and recommends movies based on the values in the file. Be sure to utilize exception handling and write unit tests.

Hannah0701 commented 4 weeks ago

Updated my intiial project code to include a people array which is updated with person objects/hashes in order to create individual packing checklists

# Get user input
puts "Welcome to my Holiday Packing Checklist Generator!"
puts "Please enter the details of your holiday:"

puts "Destination: "
destination = gets.chomp

puts "Number of people: "
num_people = gets.chomp.to_i

people = []

(1..num_people).each do |person|
    puts "Details of person #{person}:"
    puts "Name: "
    name = gets.chomp
    puts "Age: "
    age = gets.chomp.to_i
    people << {name: name, age: age}
    puts "Person #{person} added!"
end

puts "Type of holiday: "

types = ["Beach / resort holiday", "Adventure holiday", "Camping holiday", "City break", "Travel around multiple destinations"]

types.each do |type|
    puts "#{type}"
end

type = gets.chomp

puts "Duration (in days): "
duration = gets.chomp.to_i

# Generate packing checklist
packing_list = []

packing_list << "Clothes for #{duration} days"
packing_list << "Toiletries"
packing_list << "Medications"
packing_list << "Passports and travel documents"
packing_list << "Electronics (chargers, adapters, etc.)"
packing_list << "Money and credit cards"
packing_list << "Snacks and drinks for the journey"
packing_list << "Entertainment (books, games, etc.)"

if type == "Beach / resort holiday"
    packing_list << "Swimsuits"
    packing_list << "Beach towels"
    packing_list << "Sunscreen"
elsif type == "Adventure holiday"
    packing_list << "Hiking boots"
    packing_list << "Warm clothing"
    packing_list << "Trekking poles"
elsif type == "Camping holiday"
    packing_list << "Tent"
    packing_list << "Tent poles"
    packing_list << "Sleeping bag"
    packing_list << "Hiking boots"
    packing_list << "Warm clothing"
    packing_list << "Trekking poles"
elsif type == "City break"
    packing_list << "Smart dress"
elsif type == "Travel around multiple destinations"
    packing_list << "Swimsuits"
    packing_list << "Beach towels"
    packing_list << "Sunscreen"
    packing_list << "Hiking boots"
    packing_list << "Warm clothing"
    packing_list << "Smart dress"
end

packing_list << "Other miscellaneous items"

# Display packing checklist
# puts "\nHere's your packing checklist for the holiday to #{destination}:"
# packing_list.each_with_index do |item, index|
#     puts "#{index + 1}. #{item}"
# end

# Use name and age variables to create individual packing lists to display
puts "\nHere's the individual packing list for each person for the holiday to #{destination}:"
(1..num_people).each do |num|
    puts "\n#{people[num-1][:name]}'s Packing List:"
    packing_list.each_with_index do |item, index|
        puts "#{index + 1}. #{item}"
    end
end

# End of program
puts "\nHave a great holiday!"
Hannah0701 commented 4 weeks ago

Updated the packing list section of my code to try and organise items into categories

# Generate packing checklist in sections (need to create error handling for nil nil class)
packing_list = {"Important" => [], "Clothing" => [], "Personal care" => [], "Electronics" => [], "Food" => [], "Entertainment" => [], "Miscellaneous" => []}

packing_list["Clothing"] << "Clothes for #{duration} days"
packing_list["Personal care"] << "Toiletries"
packing_list["Personal care"] << "Medications"
packing_list["Important"] << "Passports and travel documents"
packing_list["Electronics"] << "Electronics (chargers, adapters, etc.)"
packing_list["Important"] << "Money and credit cards"
packing_list["Food"] << "Snacks and drinks for the journey"
packing_list["Entertainment"] << "Entertainment (books, games, etc.)"

if type == "Beach / resort holiday"
    packing_list["Clothing"] << "Swimsuits"
    packing_list["Personal care"] << "Beach towels"
    packing_list["Personal care"] << "Sunscreen"
elsif type == "Adventure holiday"
    packing_list["Clothing"] << "Hiking boots"
    packing_list["Clothing"] << "Warm clothing"
    packing_list["Important"] << "Trekking poles"
elsif type == "Camping holiday"
    packing_list["Important"] << "Tent"
    packing_list["Important"] << "Tent poles"
    packing_list["Important"] << "Sleeping bag"
    packing_list["Clothing"] << "Hiking boots"
    packing_list["Clothing"] << "Warm clothing"
    packing_list["Clothing"] << "Trekking poles"
elsif type == "City break"
    packing_list["Clothing"] << "Smart dress"
elsif type == "Travel around multiple destinations"
    packing_list["Clothing"] << "Swimsuits"
    packing_list["Personal care"] << "Beach towels"
    packing_list["Personal care"] << "Sunscreen"
    packing_list["Clothing"] << "Hiking boots"
    packing_list["Clothing"] << "Warm clothing"
    packing_list["Clothing"] << "Smart dress"
end

packing_list["Miscellaneous"] << "Other miscellaneous items"

# Display packing checklist
# puts "\nHere's your packing checklist for the holiday to #{destination}:"
# packing_list.each_with_index do |item, index|
#     puts "#{index + 1}. #{item}"
# end

# Use name and age variables to create individual packing lists to display
puts "\nHere's the individual packing list for each person for the holiday to #{destination}:"
(1..num_people).each do |num|
    puts "\n#{people[num-1][:name]}'s Packing List:"
    packing_list.each_with_index do |item, index|
        puts "#{index + 1}. #{item}"
    end
end