Question

You will create two classes and then use the provided test program to make sure your program works This means that your class

Using Python.

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

SOURCE CODE:

Car.py

class Car:
def __init__(self, make="Ford", color="black",year=1910):
self.make = make
self.color = color
self.year = year

def __eq__(self,other):
if(self.make==other.make and self.color==other.color and self.year==other.year):
return True
else:
return False
def __str__(self):
return("("+str(self.color)+","+str(self.year)+","+str(self.make)+")")


List.py

from Car import *
class List:
class Link:
def __init__(self,car):
self.car=car
self.next=None
  
def __init__(self):
self.head = None
  
def addCar(self,make,color,year):
car=Car(make,color,year)
link=self.Link(car)
link.next=self.head
self.head=link

def findCar(self,make,color,year):
car=Car(make,color,year)
itr=self.head
flag=0
while(itr!=None):
if(itr.car==car):
flag=1
return True
itr=itr.next
if(flag==0):
return False

def removeHead(self):
if(self.head==None):
return False
temp=self.head
self.head=self.head.next
return temp.car

def __str__(self):
stri=""
itr=self.head
while(itr!=None):
stri+=str(itr.car)
stri+="\n"
itr=itr.next
return stri

def __len__(self):
count=0
itr=self.head
while(itr!=None):
count+=1
itr=itr.next
return count

Test.py

from List import *

list1=List()
list1.addCar("a","blue",1991)
list1.addCar("aa","ablue",1991)
list1.addCar("b","balue",1991)
print(list1.findCar("b","baalue",1991))
list1.removeHead()
print(len(list1))
print(list1)

Screenshots:
Test.py- Test.py (3.6.1) ar.py B.6.1) List.py-C ist.py (3.6.1) File Edit Format un Options Window Help Eile Edit Format Run O False (ablue,1991,aa) (blue,1991,a)

Add a comment
Know the answer?
Add Answer to:
Using Python. You will create two classes and then use the provided test program to make sure your program works This m...
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
  • Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design:...

    Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design: You will create a class and then use the provided test program to make sure it works. This means that your class and methods must match the names used in the test program. Also, you need to break your class implementation into multiple files. You should have a car.h that defines the car class, a list.h, and a list.cpp. The link is a struct...

  • Use BlueJ to write a program that reads a sequence of data for several car objects...

    Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program...

  • Create a python program based on the following requirements the program should also have to have...

    Create a python program based on the following requirements the program should also have to have the following Base Class - Car (Make, Model, year) Sub Class - Gas (Make, Model, year, and gas per mile) Sub Class - Electric (Make, Model, year, and Full Battery charged per mile) 1. Add car 2. View car 3. Delete car 4. Exit program 1. The Car sell manager Application will need to store the car information for gas-powered car members and electric-powered...

  • *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J...

    *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...

  • Use your Car class from the previous Programming Assignment. For this assignment, create a new class...

    Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...

  • Exercise 11 - in Java please complete the following: For this exercise, you need to work...

    Exercise 11 - in Java please complete the following: For this exercise, you need to work on your own. In this exercise you will write the implementation of the pre-written implementation of the class CAR. The class CAR has the following data and methods listed below: . Data fields: A String model that stores the car model, and an int year that stores the year the car was built. . Default constructor . Overloaded constructor that passes values for both...

  • IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as...

    IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...

  • ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag...

    ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag collection using a linked list and, in order to focus on the linked list implementation details, we will implement the collection to store only one type of object of your choice (i.e., not generic). You can use the object you created for program #2 IMPORTANT: You may not use the LinkedList class from the java library. Instead, you must implement your own linked list...

  • Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...

    Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...

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
ADVERTISEMENT