close

class Teacher
  attr_accessor:name,:id,:course 
  def initialize(name,id,course)
    @name = name 
    @id = id
    @course = course
  end
  def report
    puts "I'm a teacher ,my name is "+@name+",my id is "+@id+",my course is "+@course+"."
  end
end
class Student
  attr_accessor:name,:id
  def initialize(name,id)
    @name = name
    @id = id
    @scores = []
  end
  def setScore i,s
    @scores[i] = s
  end
  def getScore i
    @scores[i]
  end
  def report
    puts "I'm a student,my name is "+@name+",my id is "+@id+",my score is "+@scores[0]+" "+@scores[1]+" "+@scores[2]+"."
  end
end
tea = Teacher.new "jhyeh","123","dynamic language"
tea.report
stu = Student.new "lupohsun","Am951180"
stu.setScore 0,"40"
stu.setScore 1,"60"
stu.setScore 2,"80"
stu.report

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 lupohsunrock 的頭像
    lupohsunrock

    lupohsunrock的部落格

    lupohsunrock 發表在 痞客邦 留言(0) 人氣()