Create a class called IS310Student. It has two methods: __init__ and speak. It also has two class attributes: classNum and finalAvg. The method or constructor __init__ constructs an object of IS310Student. It accepts three input parameters: aNum, name, finalScore. finalScore specifies the score onthe final exam of the instance being created. The class attribute IS310Student.classNum keeps track of the number of IS310Studentobjects/instances created so far. IS310Student.finalAvgkeeps track of the final average for all of the existing IS310Studentobjects.When the instance method speak() is invoked through an object, it will print out the data about that object. (100 points)

Respuesta :

Answer:

class IS310Student:

 classNum = 0

 finalAvg = 0.0

 def __init__(self, aNum, name, finalScore):

   self._aNum = aNum

   self._name = name

   self._finalScore = finalScore

   IS310Student.finalAvg = ((IS310Student.finalAvg*IS310Student.classNum) + \  finalScore)/(IS310Student.classNum+1)

   IS310Student.classNum = IS310Student.classNum + 1

 def speak(self):

   print('My name is %s and I scored %d on the final'%(self._name, self._finalScore))

s1 = IS310Student("C23", "Mike", 73)

s1.speak()

print("classNum = {0}, finalAvg = {1}".format(IS310Student.classNum, \

                                             IS310Student.finalAvg))

s2 = IS310Student("C24", "Matt", 79)

s2.speak()

print("classNum = {0}, finalAvg = {1}".format(IS310Student.classNum, \

                                             IS310Student.finalAvg))

s3 = IS310Student("C25", "Jeff", 74)

s3.speak()

print("classNum = {0}, finalAvg = {1}".format(IS310Student.classNum, \

                                             IS310Student.finalAvg))

s4 = IS310Student("C26", "Colt", 87)

s4.speak()

print("classNum = {0}, finalAvg = {1}".format(IS310Student.classNum, \

                                             IS310Student.finalAvg))

Explanation:

  • Initialize the variables and set the aNum, name, finalScore variables in the constructor.
  • Initialize an object for IS310Student class and pass the values as an argument to the constructor.
  • Call the speak method using the object of IS310Student class.
  • Display the value of final average.