Created
August 11, 2016 16:15
-
-
Save anonymous/e38544b3d12faa0cdddfbb0dc5a32196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
solution.rb:34:in `+': no implicit conversion of nil into String (TypeError) | |
from solution.rb:34:in `<main>' | |
class Person | |
def initialize(firstName, lastName, id) | |
@firstName = firstName | |
@lastName = lastName | |
@id = id | |
end | |
def printPerson() | |
print("Name: ",@lastName , ", " + @firstName ,"\nID: " , @id) | |
end | |
end | |
class Student < Person | |
def initialize(firstName, lastName, id, scores) | |
super(firstName, lastName, id,) | |
@scores = scores | |
end | |
def calculate() | |
fin = @scores.inject{ |sum, el| sum + el }.to_f / @scores.size | |
puts "O" if fin >= 90 && fin <= 100 | |
puts "E" if fin >= 80 && fin < 90 | |
puts "A" if fin >= 70 && fin <= 80 | |
puts "P" if fin >= 55 && fin < 70 | |
puts "D" if fin >= 40 && fin < 55 | |
puts "T" if fin < 40 | |
end | |
end | |
input = gets.split() | |
firstName = input[0] | |
lastName = input[1] | |
id = input[2].to_i | |
numScores = gets.to_i | |
scores = gets.strip().split().map!(&:to_i) | |
s = Student.new(firstName, lastName, id, scores) | |
s.printPerson | |
print("\nGrade: " + s.calculate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment