Comprehensive exercise of the method of object array object, our 9203 class 0912

Comprehensive exercise of the method of object array object, our 9203 class 0912

demand

Need to have a class object to manage student objects

Class description

  • Class name MyClass
  • Attribute, name, class name, initial value 9203
  • There are 29 students in the class, define an object array studentArray to save all students
  • Add student method addStudent, receive a student object, add the student to the object array studentArray
  • The method to find the student’s score, searchScore, receives the name of a student, if the student finds success, returns his score, if the search fails, returns -1
  • Random roll call method randStudent, calling this method will randomly select a student, print the student’s name and the number of roll calls, and add 1 to his roll call without returning

Student description

  • Class name MyStudent
  • Attribute, name, name
  • Attribute, score, score
  • Attribute, callNum, number of roll calls, initial value is 0

Test class description

  • Instantiate three student objects
  • Give the initial value of name, score and data customization for the three student objects
  • Instantiate a class class and get a class object
  • The class object calls the method of adding students, adding the first student, and then adding the second student, the third student
  • The class object calls the method to find the student's grade, enter a name, and get the student's grade
  • The class object calls the method of random roll call and prints relevant information. This method is executed four times, paying attention to whether the effect of random roll call is realized.

video

https://www.ixigua.com/6874571776769131021?logTag=PnVtgH_I4EKeshS_IuEKk

https://www.ixigua.com/6874577509560779278?logTag=pgRNJKfkJlRJ9CmzjDUmZ

Source code

https://cloud.189.cn/t/BNfqYrjEZNva

Guess you like

Origin blog.csdn.net/ifubing/article/details/108545799