diff --git a/main.rb b/main.rb new file mode 100644 index 00000000..3e5dc16a --- /dev/null +++ b/main.rb @@ -0,0 +1,53 @@ +require_relative "planet" +require_relative "solar_system" + +def main + solar_system = SolarSystem.new("Sol") + + elvis = Planet.new("Elvis", "shiny", 159, 20, "recorded more than 600 songs, but did not write any of them", 3.5) + hank_sr = Planet.new("Hank Sr", "white as hell", 72, 30, "recorded 14 songs as his alter ego, Luke the Drifter", 4.5) + dolly = Planet.new("Dolly", "canary yellow", 52, 18, "once entered a Dolly look-alike drag queen contest and lost", 4.8) + patsy = Planet.new("Patsy", "chesnut", 70, 40, "enjoys walking after midnight", 3.4) + garth = Planet.new("Garth", "off-white", 83, 45, "is responsible for the the most insufferable variety of country boi", 4.6) + johnny = Planet.new("Johnny", "coal black", 86, 5, "was a campaigner for Native American rights", 3.6) + reba = Planet.new("Reba", "red", 60, 10, "is the only country female solo act to have a No. 1 hit in four straight decades", 5.0) + willie = Planet.new("Willie", "old", 70, 7, "ran into a burning house to save his pound of Columbian grass", 3.8) + + solar_system.add_planet(elvis) + solar_system.add_planet(hank_sr) + solar_system.add_planet(dolly) + solar_system.add_planet(patsy) + solar_system.add_planet(garth) + solar_system.add_planet(johnny) + solar_system.add_planet(reba) + + puts "Country Music Planetary Menu\n" + puts "1. List Planets\n" + puts "2. Planet Information\n" + puts "3. Add a New Planet\n" + puts "4. Distance Calculator\n" + puts "5. Exit\n" + + loop do + "Please enter your selection from the above options." + input = gets.chomp.to_s + case + when input == "1" + puts solar_system.list_planets + when input == "2" + planet = solar_system.get_planet_name + puts planet.summary + when input == "3" + solar_system.get_info_new_planet + puts "\n...Entered into system. Thank You." + when input == "4" + solar_system.find_distance_between + when input == "5" + exit + when input =~ /[[:alpha:]]/ + puts "\nYour response was invalid" + end + end +end + +main diff --git a/planet.rb b/planet.rb new file mode 100644 index 00000000..6743b879 --- /dev/null +++ b/planet.rb @@ -0,0 +1,25 @@ + + +class Planet + attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact, :twang_level, :likelihood_to_be_loved_by_yanks + + def initialize(name, color, mass, distance_from_sun_km, fun_fact, twang_level) + @name = name.capitalize + @color = color + @mass_kg = mass_kg + @distance_from_sun_km = distance_from_sun_km + @fun_fact = fun_fact + @twang_level = twang_level + if mass <= 0 + raise ArgumentError, "Planet mass must be larger than 0" + end + if distance_from_sun_km <= 0 + raise ArgumentError, "Planet distance must be larger than 0" + end + end + + def summary + puts "The planet #{@name} is the color #{@color} has a mass of #{@mass} kg, and is #{@distance_from_sun_km} km from the sun. + It #{@fun_fact}, and is know to have a twang level of #{@twang_level} out of 5." + end +end diff --git a/solar_system.rb b/solar_system.rb new file mode 100644 index 00000000..7042d3bb --- /dev/null +++ b/solar_system.rb @@ -0,0 +1,74 @@ + + +class SolarSystem + attr_reader :solar_system_name, :planets + + def initialize(solar_system_name) + @solar_system_name = solar_system_name + @planets = [] + end + + def add_planet(new_planet) + @planets << new_planet + end + + def get_info_new_planet + print "\nWhat is your new Planet's name?" + planet_name = gets.chomp.to_s + print "\nWhat is #{planet_name}'s color?" + color = gets.chomp.to_s + print "\nWhat is the distance of planet from #{solar_system_name}(km): " + distance = gets.chomp.to_f + print "\nMass of #{planet_name}(kg): " + mass = gets.chomp.to_f + print "\nInteresting fact about #{planet_name}: " + fun_fact = gets.chomp.to_s + print "\nPlease rate the planet's twang on a scale of 0-5.0 #{planet_name}: " + twang_level = gets.chomp.to_f + + new_planet = Planet.new(planet_name, color, distance, mass, fun_fact, twang_level) + + add_planet(new_planet) + print "\nGenerating new data" + end + + def list_planets + list = "\nPlanets in the Country Music Universe:\n" + @planets.each_with_index do |planet, index| + index += 1 + list += "#{index}. #{planet.name}\n" + end + return list + end + + def find_planet_by_name(planet_name) + @planets.each do |planet| + if planet.name == planet_name.capitalize + return planet + end + end + raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" + end + + def get_planet_name + print "\nEnter planet name: " + planet = gets.chomp.to_s + return find_planet_by_name(planet) + end + + def get_planet_distance(name) + @planets.each do |planet| + if planet.name == name.capitalize + return planet.distance + end + end + raise ArgumentError, "Planet does not exist in the Country Music Hall of Planets" + end + + def find_distance_between + planet1 = get_planet_name + planet2 = get_planet_name + distance = (planet1.distance_from_sun_km) - (planet2.distance_from_sun_km) + puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." + end +end