Question: Task 1: Distance Map Requires: knowing how to design and implement a class In file distance_map.py, use the Class Design Recipe to define a class










Task 1: Distance Map Requires: knowing how to design and implement a class In file distance_map.py, use the Class Design Recipe to define a class called DistanceMap that lets client code store and look up the distance between any two cities. Your program will use an instance of this class to store the information from a map data file. If a distance from city A to city B has been stored in your distance map, then it must be capable of reporting the distance from city A to city B and of reporting the distance from city B to city A (which could be the same or different). Your class must provide a method called distance that takes two strings (the names of two cities) and returns an int which is the distance from the first city to the second, or -1 if the distance is not stored in the distance map. The doctest examples in class Fleet depend on there also being a method called add_distance. Make sure that it exists and is consistent with those doctests. The choice of data structure is up to you. For something so simple, there are surprisingly many choices. Just pick something reasonable, and be sure to define representation invariants that document any important facts about your data structure. You may find it helpful to use a default parameter somewhere in this class. Here is an example of how they work. This function takes two parameters, but if the caller sends only one argument, it uses the default value 1 for the second argument. def increase_items (lst: List[int], n: int=1) -> None: ""Mutate lst by adding n to each item. >>> grades = [80, 76, 88] >>> increase_items (grades, 5) >>> grades == [85, 81, 93] True >>> increase_items (grades) >>> grades [86, 82, 94] True == IT IT TO for i in range (len (1st)): Ist[i] += n This module contains the class Distance Map, which is used to store and look up distances between cities. This class does not read distances from the map file. (All reading from files is done in module experiment.) Instead, it provides public methods that can be called to store and look up distances. from typing import Dict class Distance Map: # TODO: Implement this class! pass if name_ == '__main__': import python_ta python_ta.check_all(config={ 'allowed-import-modules': ['doctest', 'python_ta', 'typing'], 'disable': ['E1136'], 'max-attributes': 15, }) import doctest doctest.testmod() Task 2: Modelling the Domain Requires: knowing how to design and implement a class knowing how to identify appropriate classes from a problem description Your next task is, in file domain.py to define the classes necessary to represent the entities in the experiment: classes Parcel, Truck, and Fleet. We have designed the interface for class Fleet. As you might imagine, it keeps track of its trucks, but it also offers methods that report statistics about things such as how full its trucks are, on average. (These statistics are used when we create and run instances of the Experiment class.) Class Fleet is a client of classes Parcel and Truck, so use class Fleet to figure out what services it will need from classes Parcel and Truck. (A little bit of that is already dictated by the doctest examples in class Fleet.) Then use the Class Design Recipe to help you design classes Parcel and Truck to provide those services. Start each of these two classes simply, by focusing on the data you know it must store and any operations that you are certain it must provide. Very likely, as you start to use these classes in later steps, you will add new operations or make other changes. This is appropriate and a natural part of the design process. Once you have classes Parcel and Truck completed and well tested, you can move on to implement class Fleet. Remember to do all of your work for this task in the file domain.py. This module contains the classes required to represent the entities in the simulation: Parcel, Truck and Fleet. from typing import List, Dict, Tuple from distance_map import Distance Map class Parcel: # TODO: Implement this class! # It must be consistent with the Fleet class docstring examples below. pass class Truck # TODO: Implement this class! # It must be consistent with the Fleet class docstring examples below. pass class Fleet: A fleet of trucks for making deliveries. ===== Public Attributes ===== trucks: List of all Truck objects in this fleet. trucks: List[Truck) def __init__(self) -> None: Create a Fleet with no trucks. >>> f = Fleet() >>> fnum_trucks() O # TODO: Complete this method. pass def add_truck(self, truck: Truck) -> None: "Add
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
