W
wiz_pendases
First, i need to extend the student class, and its to be enumerable by
courses. Then, show off the new functionality supported by this
change by writing an expression that returns a list of all of the
grades a student has earned in the courses he or she has completed for
the major.
here is what I got so far...what am i missing
-----------------------------------------------------------------------------------------------------------------
irb
# This class initializes a new student with ID,
# and shows a list of completed courses,
# and also shows a list of grades from completed courses.
class Student
include Enumerable
attr_reader :name, :id
# Initializing the students name and ID.
# Name = Student's name.
# ID = Student's ID.
# Initializing courses to equal a new hash.
def initialize(name, id)
@name = name
@id = id
@courses = {}
end
# Adding a course to the set of those completed.
def add_course(code, name, grade)
@courses
courses. Then, show off the new functionality supported by this
change by writing an expression that returns a list of all of the
grades a student has earned in the courses he or she has completed for
the major.
here is what I got so far...what am i missing
-----------------------------------------------------------------------------------------------------------------
irb
# This class initializes a new student with ID,
# and shows a list of completed courses,
# and also shows a list of grades from completed courses.
class Student
include Enumerable
attr_reader :name, :id
# Initializing the students name and ID.
# Name = Student's name.
# ID = Student's ID.
# Initializing courses to equal a new hash.
def initialize(name, id)
@name = name
@id = id
@courses = {}
end
# Adding a course to the set of those completed.
def add_course(code, name, grade)
@courses
Code:
= [code, name, grade]
end
# Retrieving the grade for a particular course.
def get_grade(code)
(c=@courses[code]) && c[Grade]
end
# Changing the grade for a course completed.
def set_grade(code, grade)
@courses[code][Grade] = grade
end
# Providing a list of all of the courses completed.
def list_courses
@courses.values
end
def each_grade
@courses.each { |course| yeild course }
end
end
s1 = Student.new("Eric", "00101")
s1.add_course("22c:021", "Computer Science I", "B-")
s1.each_grade.collect { |course| do course[2] }
puts s1