Question: create a ciass to store intormation about a street: Instance variables should include: the street name the length of the street ( in km )
create a ciass to store intormation about a street:
Instance variables should include:
the street name
the length of the street in km
the number of cars that travel the street per day
the condition of the street poor "fair", or "good"
Write a constructor that takes four arguments corresponding to the instance variables and creates one Street instance.
Street Class
Step :
Add additional methods:
Should return a string with the Street information neatlyformatted, as in: Elm is long, sees cars per day, and is in poor condition.
compare:
This method should compare one Street to another, with the Street the method is called on being compared to a second Street passed to a parameter.
Return True or False, indicating whether the first street needs repairs more urgently than the second.
Streets in "poor" condition need repairs more urgently than streets in "fair" condition, which need repairs more urgently than streets in "good" condition.
If the condition of two Streets is the same, the one with more traffic is given higher priority.
Street Class
Step :
Add a global constant COSTPERKM to represent how much it costs to repair each kilometer of road.
Examine the format of the file streetData.txt
Add code to read streets from file, and create a list of Street objects.
Print a list of all streets, to verify that you have read them correctly.
Print a list of the streets in poor condition, and calculate the total cost of repairing all of them.
Step : Additional Practice
Modify the code that constructs the Street list, so that the Streets are ordered by priority in the list.
Do not use a sort function. Write your own sort, or preferably, perform an ordered insert as you are reading streets from the txt file. Make use of your compare method
If you have $ million to spend on repairs, which streets could be repaired?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
