From ad57784e2aa1bc069ccd02b4684665c2ed54755a Mon Sep 17 00:00:00 2001 From: Sofia Kim Date: Tue, 14 Feb 2017 20:06:35 -0800 Subject: [PATCH 1/6] Create wave1.rb --- wave1.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 wave1.rb diff --git a/wave1.rb b/wave1.rb new file mode 100644 index 00000000..f61dbeb6 --- /dev/null +++ b/wave1.rb @@ -0,0 +1,55 @@ +#local variables will point to the planet objects +Mercury = Planet.new("Mercury", "4879", "0.39", "88days", "No" ) +Venus = Planet.new("Venus", "12104", "0.73", "225days", "No") +Earth = Planet.new("Earth", "12742", "1", "365.25days", "Yes") +Mars = Planet.new("Mars", "6779", "1.38", "1.9years", "No") +Jupiter = Planet.new("Jupiter", "139822", "5.20AU", "11.9years", "No") + +# puts Mercury.diameter +# puts Venus.diameter +# puts Mars.distance_from_the_sun +#puts Mercury.human_being_alive + +continue = true +while continue +planets = [Mercury, Venus, Earth, Mars, Jupiter] +puts "input numbers accoring to planet that you are interested in 1-Mercury, 2-Venus, 3-Earth, 4-Mars, 5-Jupiter!" + +user_input = gets.chomp.to_i +planet = planets[user_input-1] #user input is saved in planet +puts "The name of planet is #{planet.name}, diameter of #{planet.diameter}km, #{planet.distance_from_the_sun}AU, with #{planet.orbit_period}days of orbit period. Can we live there?:#{planet.human_being_alive} " + +puts "Would you like to explore anothe planet(y/n)?" +ans = gets.chomp +if ans == "n" + continue = false +end +end +#set up array of planets +#add a planet method + +class SolarSystem + + attr_reader :planets + + def initialize + @planets = [] #store planets within an array + end + + def add(planet) #in parameter no data type needed + @planets.push(planet) + end + + def print_names + @planets.each do |planet| + puts planet.name + end + end +end + +solar_system = SolarSystem.new #add planet into system local variable +solar_system.add(Venus) +solar_system.add(Mercury) +solar_system.add(Mars) +# print solar_system.planets #to view the element of @planets array instane varaible +solar_system.print_names From 2715edbaa4edad344d1fba2511ce0b8096dec8f5 Mon Sep 17 00:00:00 2001 From: Sofia Kim Date: Tue, 14 Feb 2017 20:13:40 -0800 Subject: [PATCH 2/6] Create wave2.rb --- wave2.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 wave2.rb diff --git a/wave2.rb b/wave2.rb new file mode 100644 index 00000000..5d875419 --- /dev/null +++ b/wave2.rb @@ -0,0 +1,45 @@ +#by Sofia Kim +#Create a Planet class with a name attribute. +#Allow these attributes to be set using a hash in initialize. +#You should be able to instantiate a new Planet object with an associated name. + + +class Planet + #getters/setters + attr_reader :name, :diameter, :distance_from_the_sun, :orbit_period, :human_being_alive + + #when I call .new this will be initialized as a package + def initialize(planet) + @name = planet[:name] + @diameter = planet[:diameter] + @distance_from_the_sun = planet[:distance_from_the_sun] + @orbit_period = planet[:orbit_period] + @human_being_alive = planet[:human_being_alive] #boolean + end + +end + +#add a planet method + +class SolarSystem + + attr_reader :planets + + def initialize + @planets = [] #store planets within an array + end + + def add(planet) #in parameter no data type needed + @planets.push(planet) + end + +end + +solar_system = SolarSystem.new #add planet into system local variable +solar_system.add(Planet.new(name:"Mercury", diameter:"4879", distance_from_the_sun:"0.39", orbit_period:"88days", human_being_alive:"No" )) +solar_system.add(Planet.new(name:"Venus", diameter:"12104", distance_from_the_sun:"0.73", orbit_period:"225days", human_being_alive:"No")) +solar_system.add(Planet.new(name:"Earth", diameter:"12742", distance_from_the_sun:"1", orbit_period:"365.25days", human_being_alive:"Yes")) +solar_system.add(Planet.new(name:"Mars", diameter:"6779", distance_from_the_sun:"1.38", orbit_period:"1.9years", human_being_alive:"No")) +solar_system.add(Planet.new(name:"Jupiter", diameter:"139822", distance_from_the_sun:"5.20AU", orbit_period:"11.9years", human_being_alive:"No")) + +print solar_system.planets From 14e9403ff62527d545bf95407037e7af1d65149d Mon Sep 17 00:00:00 2001 From: Sofia Kim Date: Thu, 16 Feb 2017 09:37:25 -0800 Subject: [PATCH 3/6] test --- test.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.rb diff --git a/test.rb b/test.rb new file mode 100644 index 00000000..e69de29b From 7d281a55fd22512b2d9bd57c7af2ac92086329bd Mon Sep 17 00:00:00 2001 From: Sofia Kim Date: Thu, 16 Feb 2017 09:44:09 -0800 Subject: [PATCH 4/6] remove test.rb --- test.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test.rb diff --git a/test.rb b/test.rb deleted file mode 100644 index e69de29b..00000000 From f2b87107f0a207df200d0059d600f86eddc41cfa Mon Sep 17 00:00:00 2001 From: Sofia Kim Date: Thu, 16 Feb 2017 09:48:23 -0800 Subject: [PATCH 5/6] test --- test.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.rb diff --git a/test.rb b/test.rb new file mode 100644 index 00000000..e69de29b From 10b55d67856d920db152fefd8b47c8b4eece56a6 Mon Sep 17 00:00:00 2001 From: Sofia Kim Date: Thu, 16 Feb 2017 09:51:57 -0800 Subject: [PATCH 6/6] test.rb --- test.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test.rb diff --git a/test.rb b/test.rb deleted file mode 100644 index e69de29b..00000000