Skip to content

HackerRank - Ruby - 30 days of code: added days 12 and 13 #51

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions hackerrank/ruby/30_days_of_code/day12_inheritance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Student <Person
def initialize(firstName, lastName, id, scores)
super(firstName, lastName, id)
@scores = scores
end

def calculate
avg = @scores.sum / @scores.size
case avg
when 90..100
'O'
when 80..89
'E'
when 70..79
'A'
when 55..69
'P'
when 40..54
'D'
when 0..39
'T'
end
end
end
11 changes: 11 additions & 0 deletions hackerrank/ruby/30_days_of_code/day13_abstract_classes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def initialize(title, author, price)
@title = title
@author = author
@price = price
end

def display
puts "Title: #{@title}"
puts "Author: #{@author}"
puts "Price: #{@price}"
end