Question
An odometer is the gauge on your car that measures distance traveled. In the United States, an odometer measures in miles; elsewhere else, it measures
An odometer is the gauge on your car that measures distance traveled. In the United States, an odometer measures in miles; elsewhere else, it measures kilometers. Many vehicles with electronic odometer interfaces can switch between miles and kilometers.
Something to consider: if an odometer gets replaced, a new one must be able to be set to some specified mileage.
a) Write an Odometer class which must include the following methods:
__init__ , __str__ ,__ repr__ , overloaded add and substract method o The constructor must take two arguments mileage, and any other specification that uses units (you choose the unit specification)
Both arguments must have a default value (you may choose the default values)
o Addition and subtraction - uses odometer added or subtracted from another odometer both have one odometer operand and one numeric operand, where the numeric operand represents the miles being added/subtracted (not two odometer operands). o Addition should be commutative (but not subtraction).
o Output methods should always be rounded to 1/10 mile (kilometer), but the odometer itself should maintain full floating-point accuracy.
b) Include sample code that uses your class and demonstrates the use of all methods as well as demonstrating error handling.
c) at the end of your code show an illustrated run of your code """ """
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started