最新消息:XAMPP默认安装之后是很不安全的,我们只需要点击左方菜单的 "安全"选项,按照向导操作即可完成安全设置。

Day 12

XAMPP下载 admin 619浏览 0评论
 Day 12: Inheritance
Use super to learn parent func
average = @score.sum/@score.size
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, score)
super(firstName, lastName, id)
@score = score
end

def calculate
total = @score.sum/@score.size
if total < 101 && total > 89
‘O’
elsif total < 90 && total > 79
‘E’
elsif total < 80 && total > 69
‘A’
elsif total < 70 && total > 54
‘P’
elsif total < 55 && total > 40
‘D’
else
‘T’
end
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)

转载请注明:XAMPP中文组官网 » Day 12

您必须 登录 才能发表评论!