Question

In: Computer Science

Python Programming This assignment will give you practice with interactive programs, if/else statements, collections, loops and...

Python Programming

This assignment will give you practice with interactive programs, if/else statements, collections, loops and functions.

Problem Description
A small car yard dealing in second hand cars needs an application to keep records of cars in stock. Details of each car shall include registration(rego), model, color, price paid for the car (i.e. purchase price) and selling price. Selling price is calculated as purchased price plus mark-up of 30%. For example, Toyota Corolla bought for $20,000 will have the selling price of 20000 * (1 + 0.3) = 26000.

Task Requirements
Imagine you have been invited to develop a menu driven python application to manage records of cars in stock. Based on the problem description, starter program (code template) has been provided. Investigate the provided starter program. There are four scripts(application.py, caryard.py, cars.py and vehicle.py). Driver function(main) is defined in the appliction.py, which imports caryard module(caryard.py). Caryard declares all the core functions (buy, sell, search, etc. …) for supporting the car yard business. The caryard module imports cars module(cars.py), and the cars module in turn imports the vehicle that include a definition of a Car class.
Program is executed by loading and running the application.py. The important work of interconnecting and wiring of modules and functions have been already been done. However, most of these functions, although declared and wired up in the program are not yet implemented. Your task is to implement these functions. There are eleven (11) tasks to be completed described next within the modules:

1. application.py
• Task 1: implement menu ()


2. caryard.py
• Task 2: implement buy_car ()
• Task 3: implement sell_car ()
• Task 4: implement search_car ()
• Task 5: implement list_all_cars ()


3. cars.py
• Task 6: implement addCar (rego, model, color, price)
• Task 7: implement removeCar (rego)
• Task 8: implement all_cars ()
• Task 9: implement search(rego)


4. vehicle.py
• Task 10: implement the Car class
• Task 11: UML model of a Car class

Description of Program functions:

Program displays a menu on execution. Five menu options are available to allow the user to buy, sell, search, show all cars, and exit program respectively. Program functionality and screen output for each of the menu option when selected by the user follows:

Program menu on execution:



Option 1 (Buy a car): User enters 1. Note the error message for duplicate car rego


Option 2 (Sell a car): User enters 2. Note the error message for invalid car rego, and the sell price which is a (30%) mark-up of purchase price.

Option 3 (Search): User enters 3

Option 4 (Show all): User enters 4

Option 5 (Exit Program): User enters 5

Solutions

Expert Solution

'''

Python version : 2.7

Python program to create a car class

'''

class Car:

              

               def __init__(self, rego, model, color, purchase_price):

                              self.rego = rego

                              self.model = model

                              self.color = color

                              self.purchase_price = purchase_price

                              self.selling_price = self.purchase_price*(1+0.3)

                             

               def __str__(self):

                              return('Registration : %s Model: %s Color : %s Purchase Price : $%.2f Selling Price : $%.2f' %(self.rego, self.model, self.color, self.purchase_price, self.selling_price))

                             

               def __repr__(self):

                              return('Registration : %s Model: %s Color : %s Purchase Price : $%.2f Selling Price : $%.2f' %(self.rego, self.model, self.color, self.purchase_price, self.selling_price))

                             

               def get_rego(self):

                              return self.rego

                             

               def get_model(self):

                              return self.model

                             

               def get_color(self):

                              return self.color

                             

               def get_purchase_price(self):

                              return self.purchase_price

                             

               def get_selling_price(self):

                              return self.selling_price

                             

               def set_rego(self, rego):

                              self.rego = rego

                             

               def set_model(self):

                              self.model = model

                             

               def set_color(self,color):

                              self.color = color

                             

               def set_purchase_price(self,purchase_price):

                              self.purchase_price = purchase_price

                              self.selling_price = self.purchase_price(1+0.3)

                             

#end of vehicle.py                          

Code Screenshot:

'''

Python version : 2.7

Python program to create functions to manage the list of cars

'''

from vehicle import Car

def addCar(rego, model, color, price, carList):

              

               idx = search(rego,carList)

              

               if(idx == -1):

                              carList.append(Car(rego,model,color,price))

                              return True

                             

               return False

                             

def removeCar(rego,carList):

              

               idx = search(rego,carList)

              

               if(idx != -1):

                              car = carList.pop(idx)

                              return car

               else:

                              return None

                             

def all_cars(carList):

               if(len(carList) == 0):

                              print('No cars present')

               else:      

                              for car in carList:

                                             print(car)

                             

def search(rego,carList):

              

               for i in range(len(carList)):

                             

                              if carList[i].get_rego() == rego:

                                             return i

                                            

               return -1                            

#end of cars.py

Code Screenshot:

'''
Python version : 2.7
Python program to create menu options for the main
'''

import cars

def buy_car(carList):
  
   rego = raw_input('Registration number : ')
   model = raw_input('Model : ')
   color = raw_input('Color : ')
   purchase_price = float(raw_input('Purchase price : $'))
  
   if(cars.addCar(rego,model,color,purchase_price,carList)):
       print('Car with registration : %s already exists' %(rego))
  
def sell_car(carList):
  
   rego = raw_input('Registration Number : ')
   car = cars.removeCar(rego,carList)
   if(car == None):
       print("Car with registration : %s doesn't exists" %(rego))
   else:
       print("Car sold at price : %.2f" %(car.get_selling_price()))
      
def search_car(carList):
  
   rego = raw_input('Registration Number : ')
   idx = cars.search(rego,carList)
  
   if(idx != -1):
       print(carList[idx])
   else:
       print("Car with registration : %s doesn't exists" %(rego))
      
def list_all_cars(carList):
          
   cars.all_cars(carList)
  
#end of caryard.py      

Code Screenshot:

'''

Python version : 2.7

Python program to create the main application

'''

import caryard

def main():

               carList = []

               choice = 1

               while choice != 5:

                              print('1. Buy a Car')

                              print('2. Sell a Car')

                              print('3. Search for a Car')

                              print('4. Show all cars')

                              print('5. Exit')

                             

                              choice = int(raw_input('Enter your choice : '))

                             

                              if choice == 1:

                                             caryard.buy_car(carList)

                              elif choice == 2:

                                             caryard.sell_car(carList)

                              elif choice == 3:

                                             caryard.search_car(carList)

                              elif choice == 4:

                                             caryard.list_all_cars(carList)

                              elif choice != 5:

                                             print('Invalid choice')

                              print('')

               print('Bye!')

main()   

#end of application.py                                 

Code Screenshot:

Output:

Car UML:


Related Solutions

Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value parameters, using Java objects, and graphics. This assignment has 2 parts; therefore you should turn in two Java files.You will be using a special class called DrawingPanel written by the instructor, and classes called Graphics and Color that are part of the Java class libraries.Part 1 of 2 (4 points)Simple Figure, or your own drawingFor the first part of this assignment, turn in a file named...
In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files...
In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files from the Internet. This program is very similar to wget utility in Unix/Linux environment.The synopsis of SimpleWebGet is: java SimpleWebGet URL. The URL could be either a valid link on the Internet, e.g., www.asu.edu/index.html, or gaia.cs.umass.edu/wireshark-labs/alice.txt or an invalid link, e.g., www.asu.edu/inde.html. ww.asu.edu/inde.html. The output of SimpleWebGet for valid links should be the same as wget utility in Linux, except the progress line highlighted...
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1....
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1. Describe auto-boxing, including why it is useful. (Google for this one) Write a few lines of code that auto-box an int into an Integer, and un-box an Integer to an int. 2. Declare an ArrayList of Strings. Add 5 names to the collection. "Bob" "Susan" ... Output the Strings onto the console using the enhanced for loop. 3. Sort the list using the method...
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience...
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience on the use of: 1. integers (int) 2. floats (float) 3. conditionals(if statements) 4. iteration(loops) The goal of this project is to make a fictitious comparison of the federal income. You will ask the user to input their taxable income. Use the income brackets given below to calculate the new and old income tax. For the sake of simplicity of the project we will...
COSC 1436 Programming Assignment : Skill Practice Assignment 3 Your skill practice assignment this week will...
COSC 1436 Programming Assignment : Skill Practice Assignment 3 Your skill practice assignment this week will be programming challenge #6 on page 374 - Kinetic Energy In it you are asked to write a programing that returns the amount of kinetic energy the object has. You will ask the user to enter values for mass and velocity. You will need to create a function named kinetic Energy that accepts an object's mass (in kilograms) and velocity (in meters per second)...
This problem will give you hands-on practice with the following programming concepts: • All programming structures...
This problem will give you hands-on practice with the following programming concepts: • All programming structures (Sequential, Decision, and Repetition) • Methods • Random Number Generation (RNG) Create a Java program that teaches people how to multiply single-digit numbers. Your program will generate two random single-digit numbers and wrap them into a multiplication question. The program will provide random feedback messages. The random questions keep generated until the user exits the program by typing (-1). For this problem, multiple methods...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program,...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program called randomwrite.py that writes a series of random integers to a file....
In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will...
In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. The Movie class represents a movie and has the following attributes: name (of type String), directorsName (of type String),...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT