Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON. Code that needs to be edited is at the bottom. CODE thats needs to be changed # beginning of class Student definition ------------------------- class

PYTHON. Code that needs to be edited is at the bottom.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

CODE thats needs to be changed

# beginning of class Student definition ------------------------- class Student: # class ("static") members and intended constants DEFAULT_NAME = "zz-error" DEFAULT_POINTS = 0 MAX_POINTS = 30 # initializer ("constructor") method ------------------- def __init__(self, last = DEFAULT_NAME, first = DEFAULT_NAME, points = DEFAULT_POINTS): # instance attributes if (not self.set_last_name(last)): self.last_name = Student.DEFAULT_NAME if (not self.set_first_name(first)): self.first_name = Student.DEFAULT_NAME if (not self.set_points(points)): self.total_points = Student.DEFAULT_POINTS # mutator ("set") methods ------------------------------- def set_last_name(self, last): if not self.valid_string(last): return False # else self.last_name = last return True def set_first_name(self, first): if not self.valid_string(first): return False # else self.first_name = first return True def set_points(self, points): if not self.valid_points(points): return False # else self.total_points = points return True # accessor ("get") methods ------------------------------- def get_last_name(self): return self.last_name def get_first_name(self): return self.first_name def get_total_points(self): return self.total_points # output method ---------------------------------------- def display(self, client_intro_str = "--- STUDENT DATA ---"): print( client_intro_str + str(self) ) # standard python stringizer ------------------------ def __str__(self): return self.to_string() # instance helpers ------------------------------- def to_string(self, optional_title = " ---------- "): ret_str = ( (optional_title + " name: {}, {}" + " total points: {}."). format(self.last_name , self.first_name, self.total_points) ) return ret_str # static/class methods ----------------------------------- @staticmethod def valid_string(test_str): if (len(test_str) > 0) and test_str[0].isalpha(): return True; return False @classmethod def valid_points(cls, test_points): if 0  second, and 0 if same this particular version based on last name only (case insensitive) """ fst_upper = first_string.upper() scnd_upper = second_string.upper() if fst_upper  scnd_upper: return 1 # else return 0 # beginning of class StudentArrayUtilities definition --------------- class StudentArrayUtilities: @classmethod def print_array(cls, stud_array, optional_title = "--- The Students -----------: "): print( cls.to_string(stud_array, optional_title) ) @classmethod def array_sort(cls, data, array_size): for k in range(array_size): if not cls.float_largest_to_top(data, array_size - k): return # class stringizers ---------------------------------- @staticmethod def to_string(stud_array, optional_title = "--- The Students -----------: "): ret_val = optional_title + " " for student in stud_array: ret_val = ret_val + str(student) + " " return ret_val @staticmethod def float_largest_to_top(data, array_size): changed = False # notice we stop at array_size - 2 because of expr. k + 1 in loop for k in range(array_size - 1): if Student.compare_strings_ignore_case( data[k].get_last_name(), data[k + 1].get_last_name() ) > 0: data[k], data[k+1] = data[k + 1], data[k] changed = True return changed # client -------------------------------------------- # instantiate some students, one with and illegal name ... my_students = \ [ Student("smith","fred", 95), Student("bauer","jack",123), Student("jacobs","carrie", 195), Student("renquist","abe",148), Student("3ackson","trevor", 108), Student("perry","fred",225), Student("lewis","frank", 44), Student("stollings","pamela",452) ] array_size = len(my_students) StudentArrayUtilities.print_array(my_students, "Before: ") StudentArrayUtilities.array_sort(my_students, array_size) StudentArrayUtilities.print_array(my_students, "After: ") """ ---------------------- RUN ------------------------ Before: ---------- name: smith, fred total points: 95. ---------- name: bauer, jack total points: 123. ---------- name: jacobs, carrie total points: 195. ---------- name: renquist, abe total points: 148. ---------- name: zz-error, trevor total points: 108. ---------- name: perry, fred total points: 225. ---------- name: lewis, frank total points: 44. ---------- name: stollings, pamela total points: 452. After: ---------- name: bauer, jack total points: 123. ---------- name: jacobs, carrie total points: 195. ---------- name: lewis, frank total points: 44. ---------- name: perry, fred total points: 225. ---------- name: renquist, abe total points: 148. ---------- name: smith, fred total points: 95. ---------- name: stollings, pamela total points: 452. ---------- name: zz-error, trevor total points: 108. ------------------------------------------------------------- """
Understand the Application Sort Flexibility (Student class) In week 8, we saw an example of a Student class that provided a static compare_strings_ignore_case() method. We needed to define such a method because our sort algorithm (which was in the StudentArrayUtilities (SAU) class) had to have a basis for comparing two Student objects, the foundation of SAUS sorting algorithm. Since a Student is a compound data type, not a float or a string, there was no pre-defined less-than,

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago

Question

Make efficient use of your practice time?

Answered: 1 week ago