Skip to content

Instantly share code, notes, and snippets.

@kdefliese
Last active September 29, 2015 03:52
Show Gist options
  • Save kdefliese/85e8894cd9cd6f439e42 to your computer and use it in GitHub Desktop.
Save kdefliese/85e8894cd9cd6f439e42 to your computer and use it in GitHub Desktop.
Class exercise from 9/28
class Planet
attr_accessor :name, :color, :species, :climate, :num_moons, :industry, :most_famous_inhabitant, :solar_rotation_rate, :distance_from_the_sun
def initialize(name, color, species, climate, num_moons, industry, most_famous_inhabitant, solar_rotation_rate, distance_from_the_sun)
@name = name
@color = color
@species = species
@climate = climate
@num_moons = num_moons
@industry = industry
@most_famous_inhabitant = most_famous_inhabitant
@solar_rotation_rate = solar_rotation_rate
@distance_from_the_sun = distance_from_the_sun
end
def print_out
puts "You have selected #{@name}."
puts "#{@name} is a #{@color} planet, populated mainly by #{@species}. It has a #{@climate}-type climate and the primary industry is #{@industry}."
puts "#{@name} has #{@num_moons} moons, a standard day of #{@solar_rotation_rate}, and #{@distance_from_the_sun}."
puts "#{@name}'s most famous inhabitant is #{@most_famous_inhabitant}."
end
def print_past_tense
puts "You have selected #{@name}."
puts "#{@name} was a #{@color} planet, populated mainly by #{@species}. It had a #{@climate}-type climate and the primary industry was #{@industry}."
puts "#{@name} had #{@num_moons} moon, a standard day of #{@solar_rotation_rate}, and #{@distance_from_the_sun}."
puts "#{@name}'s most famous previous inhabitant is #{@most_famous_inhabitant}."
end
end
Tatooine = Planet.new("Tatooine","orange","humans","desert",2,"moisture farming","Luke Skywalker","23 hours","is not far enough away from its two suns")
Kashyyyk = Planet.new("Kashyyyk","green","wookies","tropical forest",3,"making computer parts","Chewbacca","26 hours","is close to the sun; it is always summer there")
Alderaan = Planet.new("Alderaan","blue and green","humans","temperate",1,"manufacturing goods and electronics","Princess Leia Organa","24 hours","used to be a civilized distance from the sun, but the Empire destroyed it")
Dagobah = Planet.new("Dagobah","gray-green","insects","swamp",1,"doing, not trying","Yoda, who was a temporary inhabitant for several years","23 hours","is far away enough from the sun that the swamp never dries out")
Coruscant = Planet.new("Coruscant","gray","humans","completely citified",4,"government","The Emperor","24 hours","is a standard distance from the sun")
Endor = Planet.new("Endor","green","ewoks","jungle",0,"medicinal goods","that really cute ewok who makes friends with Princess Leia","18 hours","is actually a moon itself")
Hoth = Planet.new("Hoth","white","wampas and tauntauns","frozen",3,"freezing one's butt off while hiding from the Empire","that wampa that messed up Luke's face","23 hours","is so far from the sun that it's unclear whether it even has a sun")
Corellia = Planet.new("Corellia","blue and green","humans","temperate",3,"making starships","General Han Solo","25 hours","is a normal distance from the sun")
planets = [Tatooine, Kashyyyk, Alderaan, Dagobah, Coruscant, Endor, Hoth, Corellia]
puts "Which planet would you like to learn about today?"
puts "Please enter the name or number of the planet that you'd like to learn about, or type 'Exit' to exit"
num = 1
planets.each do |planet|
puts "#{num}. #{planet.name}"
num += 1
end
puts "#{num}. Exit"
planet = gets.chomp
# I should probably convert this to use the array for efficiency, but I like letting the user type in a planet name and am not sure how to make that work with the array
while planet != num.to_s && planet.downcase != "exit"
if planet == "1" || planet.downcase == "=tatooine"
Tatooine.print_out
puts "Would you like to learn about another planet?"
planet = gets.chomp
elsif planet == "2" || planet.downcase == "kashyyyk"
Kashyyyk.print_out
puts "Would you like to learn about another planet?"
planet = gets.chomp
elsif planet == "3" || planet.downcase == "alderaan"
Alderaan.print_past_tense
puts "Would you like to learn about another planet?"
planet = gets.chomp
elsif planet == "4" || planet.downcase == "dagobah"
Dagobah.print_out
puts "Would you like to learn about another planet?"
planet = gets.chomp
elsif planet == "5" || planet.downcase == "coruscant"
Coruscant.print_out
puts "Would you like to learn about another planet?"
planet = gets.chomp
elsif planet == "6" || planet.downcase == "endor"
Endor.print_out
puts "Would you like to learn about another planet?"
planet = gets.chomp
elsif planet == "7" || planet.downcase == "hoth"
Hoth.print_out
puts "Would you like to learn about another planet?"
planet = gets.chomp
elsif planet == "8" || planet.downcase == "corellia"
Corellia.print_out
puts "Would you like to learn about another planet?"
planet = gets.chomp
else
puts "That's not one of our planets! Would you like to learn about a planet?"
planet = gets.chomp
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment