Question

Your task in this programming assignment is to write a Python program that implements a simple...

Your task in this programming assignment is to write a Python program that implements a simple

vehicle class. The class models a vehicle that has a year, a make, and a model (e.g., 2016 Dodge Ram,

2007 Honda Civic, etc). For a 2016 Dodge Ram, for example, the year is 2016, the make is Dodge, and

the model is Ram. You will be provided a template that includes code (that you cannot change) in the

main part of the program to test the vehicle class:

# ***DO NOT MODIFY OR REMOVE ANYTHING BELOW THIS POINT!***

# the main part of the program

v1 = Vehicle("Dodge", "Ram")

v2 = Vehicle("Honda", "Odyssey")

print "v1={} {}".format(v1.make, v1.model)

print "v2={} {}".format(v2.make, v2.model)

print

v1.year = 2016

v2.year = 2016

print "v1={} {} {}".format(v1.year, v1.make, v1.model)

print "v2={} {} {}".format(v2.year, v2.make, v2.model)

print

v1.year = 1999

v2.model = "Civic"

v2.year = 2007

print "v1={} {} {}".format(v1.year, v1.make, v1.model)

print "v2={} {} {}".format(v2.year, v2.make, v2.model)

This sample code should provide some details of how to structure your vehicle class. Here's what the

output of this code with a correctly implemented vehicle class looks like:

v1=Dodge Ram

v2=Honda Odyssey

v1=2016 Dodge Ram

v2=2016 Honda Odyssey

v1=2016 Dodge Ram

v2=2007 Honda Civic

To help clarify, here are some specifics and/or constraints:

(1) The constructor must take two parameters, make and model, and make proper use of mutators to

set these values;

(2) By default, a newly instantiated vehicle has a year of 2000;

(3) Accessors and mutators (using the decorator method discussed in class) for each instance

variable (i.e., year, make, and model) must be included;

(4) A vehicle must have a year that is between 2000 and 2018 inclusive (i.e., implement range

checking so that any other provided value is ignored);

(5) You must include a meaningful header, use good coding style, use meaningful variable names,

and comment your source code where appropriate;

(6) Your output should be exactly like the sample run shown above; and

(7) You must submit your source code as a single .py file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans:-

class Vehicle(object):
def __init__(self, make, model):
self.__make = make
self.__model = model
self.__year = 2000

@property
def make(self):
return self.__make

@make.setter
def make(self,value):
self.__make = value

@property
def model(self):
return self.__model


@model.setter
def model(self,value):
self.__model = value

@property
def year(self):
return self.__year


@year.setter
def year(self,value):
if value >= 2000 and value <=2018:
self.__year = value

  


v1 = Vehicle("Dodge", "Ram")
v2 = Vehicle("Honda", "Odyssey")
print "v1={} {}".format(v1.make, v1.model)
print "v2={0} {1}".format(v2.make, v2.model)
print

v1.year = 2016
v2.year = 2016
print "v1={} {} {}".format(v1.year, v1.make, v1.model)
print "v2={} {} {}".format(v2.year, v2.make, v2.model)
print

v1.year = 1999
v2.model = "Civic"
v2.year = 2007
print "v1={} {} {}".format(v1.year, v1.make, v1.model)
print "v2={} {} {}".format(v2.year, v2.make, v2.model)
print

C Computer Scieno X G zero length field nam CentoS7-VMware Workstation 12 Player (Non-commercial use only) PlayerII . Applica

NOTE:- If u have any doubts please comment below and I am happily help to you, please thumsup bro

Add a comment
Know the answer?
Add Answer to:
Your task in this programming assignment is to write a Python program that implements a simple...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • it needs to match the sample and the code given can't be modify or removed and...

    it needs to match the sample and the code given can't be modify or removed and has to be on python 2 Your task in this programming assignment is to write a Python program that implements a simple vehicle class. The class models a vehicle that has a year, a make, and a model (c.g. 2016 Dodge Ram 2007 Honda Civic, etc). For a 2016 Dodge Ram, for example, the year is 2016, the make is Dodge, and the model...

  • Instructions ASSIGNMENT 2 is at bottom of the question. Very simple program and these intructions are...

    Instructions ASSIGNMENT 2 is at bottom of the question. Very simple program and these intructions are only to modify it slightly, should only take about 10 minutes says my proffessor. Your file should be named “Main.java”. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

  • Background: For this assignment, you will write a small encryption utility that implements a simple encryption...

    Background: For this assignment, you will write a small encryption utility that implements a simple encryption algorithm described below. The program will take one command line argument as an input; this will represent the word which is to be encrypted. As an output, your program will print the encrypted version of the word to the console using a simple printf() statement. This is the only output your program needs to produce. There is an important catch, however: your program is...

  • Python assignment:  Write a program that asks for the user's age. Based on their response print "You...

    Python assignment:  Write a program that asks for the user's age. Based on their response print "You can vote" (18 years old or older) or "You can't vote" and also whether or not he/she is a senior citizen (over 64). If senior citizen print "You're a Senior Citizen...you deserve two votes"!   Use the Idle editor and don't forget the .py extension. Good luck.          Your python program will be graded on the following:     Execution of the program gives the correct...

  • -----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer...

    -----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer to plan for retirement. Part 2: Generate a Retirement Planning Table: It's hard to decide how much you need to save for retirement. To help your customer visualize how long her nest egg will last, write a program that allows the user to generate a retirement planning table showing the number of months the savings will last for various combinations of starting account balance...

  • C++ Assignment Write a program that calculates the total weight of one vehidle and one cargo...

    C++ Assignment Write a program that calculates the total weight of one vehidle and one cargo vehicle. For both vehicles, the user will give the base weight of the vehicle, the passenger capacity of the vehicle, and ONLY FOR the cargo vehicle, the cargo weight capacity all as integers. Then, the user will give passenger information for BOTH vehicles as first the number of passengers and weights of each passenger (e.g., 2 60 80 means two passengers of weight 60...

  • Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born...

    Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...

  • help me Problem: Write a simple C program that calculates the corresponding y-coordinate for any x-coordinate...

    help me Problem: Write a simple C program that calculates the corresponding y-coordinate for any x-coordinate onaline defined by two points. These points areinputspecifiedas pairsofxandycoordinates in the two-dimensional Cartesian coordinate system. Youneed to determine the slope ofthe line and they-intercept for the line plotted by these two points and store this data in memory. The programmustpromptthe userforthe coordinates of the first point X1 and then Y1, and then prompt the user for the second point, X2 and then Y2. After...

  • Develop a Java application that provides program output in a logical manner and incorporates appropriate data...

    Develop a Java application that provides program output in a logical manner and incorporates appropriate data types. Similar to zyBooks examples in Chapter 2, your program should prompt a user to enter a car brand, model, year, starting odometer reading, ending odometer reading, and gallons used. The output should include this information along with the estimated miles per gallon consumed by the vehicle in the format MPG: your calculation. Print each on separate lines with the appropriate labels (example, MPG:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT