Starting from:

$34.99

CS104 Homework 09 Solution


1.  Please implement a Circle class where you can generate objects in the following way:
c = Circle(x, y, r);
# x: x coordinate of center
# y: y coordinate of center
# r: radius
Add a method named “touches” to this Circle class which receives another Circle instance and checks whether these two circles touch each other externally and only at one point. The method should return a Boolean value and will be called like this:
c1.touches(c2) # returns either true or false.
Please implement assertions that simulates each of the following cases.

2. Please check the diagram which describes a scenario for some states of a TeaCup object.

◦ Please implement the TeaCup class with necessary attributes that will help you define possible steps.
◦ Please implement the necessary methods (methodA, methodB, methodC, methodD and methodE). Please rename them so that their behavior can be better understood by the users of the class.
◦ Implement a report() method in the TeaCup class which prints information about object’s state.
◦ Implement a test function which simulates construction of an object (in State 1) and calls methodA, methodB, methodC, methodD, methodE, methodD sequence. Please verify your state changes by assertions.
3. (25 pts) Implement a Car class. A Car object has the following information: odometer, brand, color, and gear.
◦ You will be creating brand new Car objects with odometer set initially to 0.
◦ Implement methods increment_gear() and decrement_gear() to increment or decrement the gear. It is initially set to 0.
◦ Implement a drive() method which takes two arguments: (1) Number of hours traveled and (2) km traveled per hour. This function is going to be used to modify the odometer.
◦ Implement a method named display() to display the information of a car.
◦ Implement a test method that creates three Car objects. Assign their brand, color and gear. Then, call their display() methods to print their information.
4. (25 pts) Please revisit the second question in Homework 06. Check the file called “students.dat”. In this file, there are 6 columns representing number, name, surname, birth place, department and GPAs of students. Implement a Student class and define attributes for this class (based on the columns of this file). Please read the data from the file and generate Student objects for each line and put them into a dictionary (called students) where key is the student number and value is the Student object. You are not allowed to modify the input file. Additionally implement, five functions in Student class that print the necessary information.
For example, when you say students[81709043].print_birth_place(), it shall print “Detroit”.
• students[student_number].print_name()
• students[student_number].print_surname()
• students[student_number].print_birth_place()
• students[student_number].print_department()
• students[student_number].print_gpa()

More products