Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kayla's Mario Themed Solar System #32

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
579ba95
Initial commit of class planet document. So far constructor and reade…
Kaylaj89 Sep 22, 2020
a9ee4f3
updated planet and created main.rb file
Kaylaj89 Sep 22, 2020
53d51f5
Added solar system to project
Kaylaj89 Sep 22, 2020
78bb624
Working on def summary
Kaylaj89 Sep 22, 2020
d210618
added a test file for planet
Kaylaj89 Sep 22, 2020
d710124
created new instance of earth and tested code from planet class
Kaylaj89 Sep 22, 2020
260d7d4
Added the summary block and added optional data validation for mass a…
Kaylaj89 Sep 22, 2020
17f2edb
Trying to get logic in minitest to run for ArgumentError, but no luck
Kaylaj89 Sep 22, 2020
4276d83
Solved issues with tests and it will now properly test for ArgumentEr…
Kaylaj89 Sep 22, 2020
d18bf0c
Added 2 new methods 'add_planet' and 'list_planets'
Kaylaj89 Sep 22, 2020
c0b3a8f
Added an instance of found_planet to the main rb
Kaylaj89 Sep 23, 2020
a808e92
Had to rework @mass_kg and @distance from sun--added the validation d…
Kaylaj89 Sep 23, 2020
131b7fd
Added find_planet_by_name method
Kaylaj89 Sep 23, 2020
8d49a9d
found bug in 'view planet details' option...but now gone
Kaylaj89 Sep 23, 2020
0edd1e4
Added 'return' to summary method
Kaylaj89 Sep 23, 2020
fd7b3ec
Not sure what the change was, but pushing it through
Kaylaj89 Sep 23, 2020
5d7310b
program fully functional. Fixed loop so that it only quits when user …
Kaylaj89 Sep 23, 2020
d9a985c
Added 'add_new_planet' method to solar system
Kaylaj89 Sep 23, 2020
99e7f65
added colorize gem
Kaylaj89 Sep 23, 2020
4a9b778
added colorize gem
Kaylaj89 Sep 23, 2020
1086e06
added colorize gem
Kaylaj89 Sep 23, 2020
b32b4cb
required colorize gem so that test works properly
Kaylaj89 Sep 23, 2020
b0381c5
added some clarifying comments to 'add_new_planet' method
Kaylaj89 Sep 23, 2020
03ae035
added comment to add_new_planet method
Kaylaj89 Sep 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
require_relative 'planet'
require_relative 'solar_system'
require 'colorize'
require 'colorized_string'

def main

#Create a solar system, planets, and add them to the planets array in the solar system
solar_system = SolarSystem.new("luna")

koopa_troopa_town = Planet.new("koopa troopa town","red and green", 6.972e24, 1.283e7, "It takes a while for inhabitants to come out of their shell.")
solar_system.add_planet(koopa_troopa_town)

yoshi_land = Planet.new("yoshi land", "green", 2, 1.5, "My full planet name is T. Yoshisaur Munchakoopas" )
solar_system.add_planet(yoshi_land)

mario_world = Planet.new("mario world", "red", 5.432e56, 100000, "You'll find that everything here is super!")
solar_system.add_planet(mario_world)

earth = Planet.new("earth", "blue-green",6.972e24,1.283e7,"I live on it")
solar_system.add_planet(earth)

bowserville = Planet.new("bowserville", "orange, red, and green", 100000000e34, 60000, "Bwa ha ha ha!" )
solar_system.add_planet(bowserville)

luigi_lagoon = Planet.new("luigi lagoon", "green", 343439, 232939, "Luigi TIme!!")
solar_system.add_planet(luigi_lagoon)

princess_peach_paradise = Planet.new("princess peach paradise", "peach", 34342, 45645, "Peachy!")
solar_system.add_planet(princess_peach_paradise)



#Control loop that repeatedly asks user what to do next
# Only way to exit program is to type 'exit'
repeat = true
until repeat == false
puts
puts "*" * 50
puts "Marioooo time! What would you like to do next?\nYou can:\n".colorize(:light_green)
puts "1. See a list of planets by typing 'list'\n"
puts "2. View planet details of your favorite planet by typing 'details'\n"
puts "3. Add a planet to the Mario Universe collection by typing 'add'\n"
puts "4. Exit the program by typing 'exit'\n\n"
puts "Waiting for your input.... "
input = gets.chomp

case
when input == "list"
list = solar_system.list_planets
puts list
when input == "details"
puts "What planet are you interested in learning more about?"
input = gets.chomp.to_s
summary = solar_system.find_planet_by_name(input)
puts summary
when input == "add"
solar_system.add_new_planet
puts "Let's see your new planet!"
when input == "exit"
exit
else
puts "\nInvalid Entry. Please read the instructions carefully and retype your answer.".upcase.colorize(:red)
end
end
end

main














# main
#

# end
# main
21 changes: 21 additions & 0 deletions planet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Planet

attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact

def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact)
@name = name
@color = color
@mass_kg = mass_kg
raise ArgumentError, 'Mass must be greater than 0.' if mass_kg < 0
@distance_from_sun_km = distance_from_sun_km
raise ArgumentError, 'Distance from sun must be greater than 0.' if distance_from_sun_km < 0
@fun_fact = fun_fact
end

def summary
summary = "\n Name: #{@name}\n Color: #{@color}\n Mass: #{@mass_kg}\n Distance from the Sun:#{@distance_from_sun_km}\n Fun Fact: #{@fun_fact}\n\n".colorize(:green)
return summary
end

end

39 changes: 39 additions & 0 deletions planet_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'minitest/autorun'
require 'minitest/reporters'
require_relative 'planet'
require 'colorize'
require 'colorized_string'

Minitest::Reporters.use!

describe "planet" do

it "will return a string" do

#Arrange
earth = Planet.new("earth", "blue-green",5,2,"I live on it")

#Act
puts earth.summary

#Assert
expect(earth.summary).must_be_instance_of String
end

it "will raise an error if mass_kg is less than 0" do

#Assert
expect {
Planet.new("earth", "blue-green",-5,2,"I live on it")
}.must_raise ArgumentError
end

it "will raise an error if distance_from_sun_km is less than 0" do
#Assert
expect {
Planet.new("earth", "blue-green",5,-2,"I live on it")
}.must_raise ArgumentError

end

end
57 changes: 57 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require_relative 'planet'
require 'colorize'
require 'colorized_string'

class SolarSystem

attr_reader :star_name, :planets

def initialize(star_name)
@star_name = star_name
@planets = []
end

def add_planet(planet)
@planets << planet
end

def list_planets
list = "\nPlanets orbiting #{star_name}:\n".colorize(:green)
@planets.each_with_index do |planet, index|
index += 1
list += "#{index}. #{planet.name}\n"
end
return list
end

def find_planet_by_name(input_name)
@planets.each do |single_planet|
return single_planet.summary if single_planet.name.downcase == input_name.downcase
end
return "\nSorry,this planet is in the process of being created many light years away and cannot be located just yet.".upcase.colorize(:red)
end

#Add argument error to mass and distance input since they are not going through the initialize function
def add_new_planet
puts "It's a-me, Mario! Add some information about your new planet:"
puts "name:"
new_name = gets.chomp
puts "color:"
new_color = gets.chomp
puts "mass_kg (integer only - do not spell out number):"
new_mass = gets.chomp.to_i
if new_mass < 1
raise ArgumentError, 'Mass must be an integer and it must be greater than 0.'.colorize(:yellow)
end
puts "distance from sun (integer only - do not spell out number):"
new_distance = gets.chomp.to_i
if new_distance < 1
raise ArgumentError, "Distance from sun must be greater than 0.".colorize(:yellow)
end
puts "What is your fun-a fact?"
new_fun_fact = gets.chomp

new_name = Planet.new(new_name,new_color,new_mass,new_distance,new_fun_fact)
add_planet(new_name)
end
end