CPT 310 HW 5-2

pdf

School

New Jersey Institute Of Technology *

*We aren’t endorsed by this school

Course

310

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

2

Uploaded by ChiefGalaxySnail36

Report
O’Neil Montague December 4, 2022 Homework 5 # Vehicle class definition ~~~~~~~~~~~~ Class definition class Vehicle: # constructor to initializing #value # associates identifier with 3 classes def __init__ ( self , make , model , color): self .make = make self .model = model self .color = color # gatter method # Gatter the 3 different identifications/classes def getMake ( self ): return self .make def getModel ( self ): return self .model def getColor ( self ): return self .color # Car class that is child class of Vehicle # associates child classes class Car(Vehicle): # constructor to initializing value # calling full object with classes def __init__ ( self , make , model , color , engineSize , numDoors): Vehicle. __init__ ( self , make , model , color) # calling primary class self .engineSize = engineSize self .numDoors = numDoors # getter method # for other 2 child classes def getEngineSize ( self ): return self .engineSize def numDoors ( Self ): return Self .numDoors # print details method to print data # associate name/print to classes def printDetails ( self ): print ( "Car Make : " , self .make) print ( "Car model : " , self .model) print ( "Car Color : " , self .color) print ( "Car Engine Size : " , self .engineSize) print ( "Car Number of Doors :" , self .numDoors) garage = [] # list to hold Vehicle objects while ( True ): # loop that will take user input
option = int ( input ( "Enter \n 1 for Car \n 2 for Pickup \n 3 for exit \n " )) ^^ # option from which user can choose ^^ if (option == 1 ): # if 1 Car data is to be added make = input ( "Enter Car Make : " ) model = input ( "Enter Car Model : " ) color = input ( "Enter Car Color : " ) engineSize = int ( input ( "Enter Car Engine Size : " )) numDoors = int ( input ( "Enter Car Number of Doors : " )) p = Car(make , model , color , engineSize , numDoors) # creating car object garage.append(p) # adding car object to garage list else : # if other option is entered then exit code break # printing vehicle details print ( "Vehicles Details is :" ) print ( "---------------------------" ) for v in garage: print (v.printDetails()) # calling printDetails method
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help