IT 212 -- Takehome Final Exam Name _________________ Opens: November 11, 2020 Closes: November 22, 2020 Include this line at the top of your submission for Part A: I completed this exam by myself without the help of any other persons. Deliverables: A single zipfile with your files named THFSmith.zip; replace Smith with your last name. Part A. Answer 3 of 5 questions. Submit MS Word or Text file. 10 pts each. Part B. Python modules student.py and test2.py: 10 points each. Part C. Corrected modules person.py, driver.py, test3.py: 10 pts each; error log for modules person.py, driver.py, test3.py: 10 pts. Part D. Corrected Java file Converter.java: 15 points; error log: 10 pts. The total points 115 will be converted to a score out of 100 and further scaled if necessary. Part A. Short Essay Questions (30 pts). For full credit, write in full sentences paragraphs. If you look up information in the IT 212, Lecture Notes or other sources, cite your sources. Your audience should be someone that understands programming, but is not an expert in Python or Java. Answer 3 out 5 essay questions. 1. Explain why inheritance is useful in Python software development. Give examples. 2. What are dunder methods, also called magic methods? How are they used when writing Python classes. Give examples. 3. Discuss the similarities and differences between a Python list and a Python dictionary. 4. Explain what regular expressions are and how they are used in Python scripts. Give examples. 5. Explain how to use Python to create, populate, and query SQLite databases. Part B. Create and Test Class (40 pts). Create and test a Student class according to the UML diagram later in this Part B section. A Student object represents a student in a course that only requires a midterm and a final exam. The instance variables for the Student class are id, name, midterm, final. The course score is computed like this: course_score = midterm * 0.4 + final * 0.6 The course grade is computed from the course score is computed with these specifications: grade is A if course score >= 89.5, grade is B if course score < 89.5 and score > 79.5, grade is C if course score < 79.5 and score > 69.5, grade is D if course score < 69.5 and score > 59.5, grade is F if course score < 59.5. Also create a traditional test script test1.py and a unit test script test2.py that test all public instance members: id, name, midterm, final, the constructor, str, and compute_course_grade. Test each possible return value of compute_course_grade. Here is the UML diagram: +--------------------------------------------------+ | Student | +--------------------------------------------------+ | + id : int | | + name : str | | + midterm : float | | + final : float | +--------------------------------------------------+ | - __init__(self : Student, id : int, name : str, | | midterm : str, final : str) | | - __str__(self : Student) : str | | + compute_course_grade(self : Student) : str | +--------------------------------------------------+ Part C: Find Errors (30 pts) Find the errors in the modules person.py, driver.py, test3.py. The module person has no errors. Adding, removing, or changing ( ), [ ], { }, ' ', " ", only counts as one error. Don't forget the error log showing all the errors in the three modules person.py, driver.py, test3.py. # --- person.py module ------------------------------------ class Person: def __init__(name, gender, eye_col, ht, wt): self.name = name self.gender = gender self.eye_color = eye_col self.height = ht weight = wt def __str__(self) return '{0:s} {1:s} {2:s} {3:d} {4:d}'.\ format(self.name, self.gender, self.eye_color,\ self.height, self.weight) def __repr__(self): return str(self): def __lt__(self, other): return self.name > other.name # --- driver.py module ------------------------------------ from person import Person class Driver[Person]: def __init_(self, name, gender, eye_col, ht, wt, num): super( ).__init__(name, gender, eye_col, ht, wt) num = self.license_num self.violation_points = 0 def __str__(self): return f'{super( ).__str__( )} ' +\ f'{self.license_num} {self.violation_points}' def add_points(pts, self): if pts > 0: self.violation_points + = pts def clear_points(self): self.violation_points = 0 # --- test3.py module ------------------------------------- from driver import Driver drivers = [ ] fin = open(drivers.txt, 'r') fin.readline( ) for line in fin: f = line.strip( ).split(',') d = Driver(f[0], f[1], f[2], int(f[3]), int(f[4]), int(f[5])) drivers.append(d) fin.close( ) drivers[3].add_points(25) drivers[0].add_points(50) drivers[1].add_points(-15) drivers.sort( ) for d in drivers: print(d) for d in drivers: d.clearPoints( ) print(drivers) # --- input file drivers.txt ------------------------------ name gender eye_col ht wt lic_num Julia F brn 65 115 H3443J345 Scott M blu 74 185 H2543J987 April F grn 63 103 H1210J221 Mark M brn 70 179 H7269J521 # --- output from running test3.py with corrected modules April F grn 63 103 H1210J221 0 Julia F brn 65 115 H3443J345 50 Mark M brn 70 179 H7269J521 25 Scott M blu 74 185 H2543J987 0 [April F grn 63 103 H1210J221 0, Julia F brn 65 115 H3443J345 0], Mark M brn 70 179 H7269J521 0, Scott M blu 74 185 H2543J987 0] # --------------------------------------------------------- Part D: Find Errors (25 pts) Find the errors in the the Java source code file. This is a translation of the Python script in Lab 1 that converts meters to feet and inches. Adding, removing, or changing ( ), [ ], { }, ' ', " " only counts as one error. Switching two lines also only counts as fixing one error. Don't forget the error log. import java.util.Scanner; public class Converter { private static String toFeetInches(double meter) { double feetAndFraction = meter * 3.28084; int feet = (int) feetAndFraction; int inches = (int) Math.round((feetAndFraction - feet) * 12.0); String feetString = "", inchesString = ""; if (feet = 1) { feetString = feet + " foot "; } else { feetString = feet + " feet "; } if inches > 1 { inchesString == inches + " inches"; } else if inches == 1 { inchesString = inches + " inch"; } elif (inches == 0) { inchesString = ""; } return feetString + inchesString; } public void main(String[ ] args) { Scanner s = new Scanner("System.in"); System.out.print("Enter a length in meters: "); System.out.println(toFeetInches(m)); double m = Double.parseDouble(s.nextLine( )); } Here is the correct translation of Converter.java into Python. Note that the Converter class and the main method are not explicit in the Python version. def to_feet_inches(meter): feet_and_fraction = meter * 3.28084 feet = int(feet_and_fraction) inches = int(round((feet_and_fraction - feet) * 12.0)) feet_string = '' inches_string = '' if feet == 1: feet_string = str(feet) + ' foot ' else: feet_string = str(feet) + ' feet ' if inches > 1: inches_string = str(inches) + ' inches' elif inches == 1: inches_string = str(inches) + ' inch' elif inches == 0: inches_string = '' return feet_string + inches_string # Start of main standalone script m = float(input('Enter a length in meters: ')) print(to_feet_inches(m));