Lab 12: Classes
Points Possible: 100
Due: Thursday, November 21st
In this lab, we will write programs using Python classes.
Submission:
- Submit a Python file for each of the programs.
Program 1: Triangle
Design a class named Triangle. The Triangle class contains:
- Three float data fields named
side1,side2andside3to denote the three sides of the triangle. - A constructor that creates a triangle with the specified
side1,side2andside3with default values 1.0. - A method named
getArea()that returns the area of the triangle. - A method named
getPerimeter()that returns the perimeter of the triangle.
Write test code that prompts the user to enter three sides of a triangle. The program should create a triangle object with these sides and display the triangle’s area and perimeter.
Formula:
\[s = (side1 + side2 + side3) / 2\] \[area=\sqrt{s(s-side1)(s-side2)(s-side3)}\]Save the program as triangle.py and attach it to the Blackboard lab assignment.
Draw a UML diagram for the Triangle class and attach it to the Blackboard lab assignment. You can take a picture of the diagram, or use an online tool.
Grading Rubric for the program:
(Comments: 5 points, class and methods: 30 points, UML: 5 points, test program: 5 points, UML: 5 points)
Total: 50 points
Program 2: Practice
Create a class Practice that contains the following data fields:
list1dict1
Methods:
__init__that will initializelist1anddict1.getListthat will returnlist1setListthat will setlist1getDictthat will return thedict1setDictthat will set thedict1findMinListthat returns the minimum values inlist1.findMaxListthat returns the maximum values inlist1.findSumDictthat returns the sum of values indict1.
Write a test code that creates an instance of the Practice class and pass values for list and dictionary (you can use any arbitrary values). Print the minimum and maximum values in the list by calling the methods. Also, print the sum of values in dictionary by calling the findSumDict method.
Save the program as Practice.py and attach it to the Blackboard lab assignment.
Grading Rubric for the program:
(Comments: 5 points, class and functions: 40 points, test program: 5 points)
Total: 50 points