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
- Oct 23 Thu 2008 15:40
Program #1: Write a class scoring system, part I.
close
全站熱搜
留言列表