Lab 8/Additional Exercises.txt == Patient Roster == Context: an appointment system for a doctor's office. A doctor has patients, each of whom has an OHIP number, family name, first name and gender....

1 answer below »
The instruction is in the lab 8 pdf file


Lab 8/Additional Exercises.txt == Patient Roster == Context: an appointment system for a doctor's office. A doctor has patients, each of whom has an OHIP number, family name, first name and gender. The doctor has a limit on the number of patients they can take. The doctor may have a gender balance rule: a limit on the difference between the number of male and female patients they are willing to have. When a patient asks to register with the doctor, they will be successful only if the doctor is not at his or her limit and the patient will not violate the doctor's gender balance rule. Sometimes patients move, change doctors, or die, and in those cases they need to be removed from the doctor's list. Design and implement a class for a patient roster. == Class List == Context: a student records system like STUVIEW A course has students in it. Each student is identified by a unique student number. There is a limit on how many students can register, but that limit can change. Students are allowed to add and drop the course. Design and implement a class for a class list. == Flight Roster == Context: An airline reservation system Each seat has a unique name, like "17C" and is either in business class or economy. Passengers have booking IDs (a mix of letters and numbers). When they book a seat, they request their preferred class (business or economy) and are given any seat in that class. If the class is full, their booking is unsuccessful. This airline gives passengers no choice about their specific seat. We want to be able to report on how full a flight is: the percentage of seats that are booked in economy, in business class, and overall. Design and implement a class for a flight roster. == Player == Context: an app for a game like 2048 or PacMan, where players get a score each time they play. A player has a name and a history of the last 100 scores they've achieved in the game. We need to keep track of new scores they get so we can determine their top score and their average score on their most recent n games, where n is some positive whole number. Design and implement a class for a player. == Inventory Item == Context: an inventory system Items are for sale, each one at its own price. Items are identified by their item number, and they also have a text description, such as "bath towel". There are categories that items belong to, such as "housewares" and "books". We need to be able to print a suitable price tag for an item (you can decide exactly the format). Sometimes an item is discounted by a certain percentage. We need to be able to compare two items to see which is cheaper. Design and implement a class for an inventory item. Lab 8/balloon_exercise(2).pdf COMP2152 Winter 2018 build Balloon class Somewhere in the real world there is a description of balloons: A balloon is an in�atable plastic toy that comes in various colors. Di�erent balloons may have di�erent colors. A balloon can be in�ated up to a maximal capacity, often described in cubic centimeters. An attempt to overin�ate the balloon, may result in the balloon become popped, therefore incapable of holding air. When a balloon is manufactured new, it is not popped an contains a volume of air equal to zero cubic centimeters. When used, a ballon may contain a volume of air less or equal to its capacity. Some typical operations that one associates with balloons, are in�ating a balloon, or playing with it. Find the most important noun (good candidate for a class. . . ), its most important attributes, and operations that sort of noun should support. Below are steps taken for designing Python classes. You'll be using this in more depth next week during lab, but for now we'll use it as a guide to creating the Balloon class. Here are exercises to carry out on paper, perhaps you'll need some scrap paper as well as this hand-out. You are, of course, welcome, to continue the exercise on a computer in Python. Part 1: De�ne the API for the class 1. Class name and description. Pick a noun to be the name of the class, write a one-line summary of what that class represents, and (optionally) write a longer, more detailed description. Save your code in a �le named balloons_exercise.py. A sample is provided below. class Balloon: """ A balloon with a specific colour and capacity. """ 2. Public attributes. Decide what data you would like client code to be able to access without calling a method. Add a section to your class docstring after the longer description, specifying the type, name, and description of each of these attributes. An example is shown below: class Balloon: """ A balloon with a specific colour and capacity. === Attributes === @type capacity: float maximal volume of the balloon, in cubic centimeters @type volume: float current volume of the balloon, in cubic centimeters @type colour: str 1 the colour of the balloon @type popped: bool the state of the balloon, True if and only if the balloon is popped """ 3. Representation invariants. One of the main bene�ts of creating a class to represent a new type of data is being able to precisely describe the structure of the instance attributes for that class. Often, just specifying the types of the attributes, as we did in the Balloon docstring above, is not enough to restrict the values of the attributes that we want. For example, the capacity of a Balloon must be a positive number, and its volume must be a non-negative number ; if we truly wanted to model a balloon, we would like some way of specifying this restriction as well. Such restrictions on the values of attributes are called representation invariants for a class; it is our responsibility as the designers of a class to both document all representation invariants carefully, as well as ensure that our constructor (and later, other methods), enforce these invariants. attributes. An example is shown below: class Balloon: """ A balloon with a specific colour and capacity. === Attributes === @type capacity: float maximal volume of the balloon, in cubic centimeters @type volume: float current volume of the balloon, in cubic centimeters @type colour: str the colour of the balloon @type popped: bool the state of the balloon, True if and only if the balloon is popped === Representation invariants === - capacity > 0 - volume >= 0 """ 4. Public methods. Decide what services your class should provide. For each, de�ne the API for a method that will provide the action. Use the �rst four steps of the Function Design Recipe to do so: (1) Example (2) Type Contract (3) Header (4) Description A sample for one of the possible methods for the Balloon class has been provided below: def is_popped(self): """ Returns the state of the balloon @type self: Balloon @rtype: bool >>> b = Balloon(500.0, "blue") >>> b.is_popped() False """ Part 2: Implement the class 1. The constructor. The constructor, __init__, is a special method that performs the crucial operation of initializing the instance attributes of a newly created instance of a class. Use the last two steps of the function design recipe to implement it. Example: def __init__(self, capacity, colour): """ Create a new Balloon self with given capacity, given colour, a zero volume, and not popped. @type self: Balloon @type capacity: float @type colour: str @rtype: None Precondition: capacity must be a positive float >>> b = Balloon(500.0, "blue") >>> b.capacity 500.0 """ self.capacity = capacity self.colour = colour self.volume = 0 self.popped = False Please note, just stating the preconditions (in accordance with representation invariants!) will not prevent other from violating those. 2. Public methods. Use the last two steps of the function design recipe to implement all of the methods: (5) Code the Body (6) Test your Method As an example, here is the code for is_popped: def is_popped(self): """ Returns the state of the balloon @type self: Balloon @rtype: bool >>> b = Balloon(500.0, "blue") >>> b.is_popped() False """ return self.popped 3. Example. Write some simple examples of client class that uses your class. from balloons_exercise import Balloon class BalloonParty: """ A BalloonParty object simulates a balloon party === Attributes === @type balloons: list of Balloon objects """ def __init__(self, balloons): """ Create a BalloonParty object with a list of balloons @type balloons: list of Balloon objects @rtype: None >>> my_party = BalloonParty([Balloon(200.0, "red"), Balloon(300.0, "blue")]) >>> len(my_party.balloons) 2 """ self.balloons = balloons if __name__ == "__main__": import doctest doctest.testmod() Lab 8/lab8(1)(2).pdf COMP2152, Lab #8, Winter 2018 Introduction The goals of this lab are: � To give you practise designing a class. Object-oriented analysis was discussed last lecture. � To give you practise implementing a class, pelase review the balloon exercise (solved for you). Designing a class 1. Create a new �le called lab08.py. 2. Perform an object-oriented analysis of the speci�cations in specs.txt, following the same recipe we used in class for Point: 3. choose a class name and write a brief description in the class docstring. 4. write some examples of client code that uses your class 5. decide what services your class should provide as public methods, for each method declare an API (examples, header, type contract, description) 6. decide which attributes your class should provide without calling a method, list them in the class docstring This analysis will require a fair amount of thought. Don't worry about getting it completely right: you need to leave enough time to get to the next steps where you will implement your design. If you're stuck, you may look at the ballon example, and/or ask your instructor. Implementing a class 1. write the body of special methods __init__, __eq__, and __str__ 2. write the body of other methods 3. Save your modi�ed �le lab08.py. 1 Using your class 1. Create a new �le named lab08tester.py where you will carry out the following tasks, under if __name__ == "main": � from lab08 import NameOfYourClass (but replace NameOfYourClass with the actual name of the class you wrote). You may need to review how to import names of Python objects such as classes. � Create a race registry. � Register the following runners: [email protected] (with time under 40 minutes), [email protected] (with time under 30 minutes), [email protected] (with time under 20 minutes), [email protected] (with time under 30 minutes), [email protected]
Answered 3 days AfterAug 17, 2021

Answer To: Lab 8/Additional Exercises.txt == Patient Roster == Context: an appointment system for a doctor's...

Arun Shankar answered on Aug 21 2021
160 Votes
class Player:
def __init__(self, name, category):
self.name = name
self.category = cate
gory

def get_category(self):
return self.category

def get_name(self):
return self.name
class RaceRegistry:
def __init__(self):
self.players = list()
def add_player(self, player):
self.players.append(player)
def look_up_category(self, playername):
for player in self.players:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here