Question

In: Computer Science

We have a class defined for vehicles. Create two new vehicles called car1 and car2. Let...

We have a class defined for vehicles. Create two new vehicles called car1 and car2. Let car1 to be a red convertible worth $60,000.00 with a name of Fer, and car2 to be a blue van named Jump worth $10,000.00.

# define the Vehicle class

class Vehicle:

             name = ""

             kind = "car"

             color = ""

             value = 100.00

  

def description(self):

                         print (“Name of car =”,self.name)

print (“Kind of car =”,self.kind)

print (“Color of car =”,self.color)

print (“Value of car =”,self.value)

# test code

car1.description()

car2.description()

Using the program above, add in your own codes in order to complete the program to produce the output as below:

Name of car = Fer

Kind of car = Convertible

Color of car = Red

Value of car = $60,000

Name of car = Jump

Kind of car = Van

Color of car = Blue

Value of car = $10,000

#Python

Solutions

Expert Solution

# define the Vehicle class
class Vehicle:
   name = ""
   kind = "car"
   color = ""
   value = 100.00

   def description(self):
       print ("Name of car =",self.name)
       print ("Kind of car =",self.kind)
       print ("Color of car =",self.color)
       # introduce $ sign and a comma in value
       print ("Value of car =",'${:,}'.format(self.value))

   # define a constructor for the Vehicle class
   def __init__(self,newName,newKind,newColor,newValue):
       self.name = newName
       self.kind = newKind
       self.color = newColor
       self.value = newValue

# car1 - a red convertible worth $60,000.00 with a name of Fer
car1 = Vehicle("Fer","Convertible","Red",60000)

# car2 - a blue van named Jump worth $10,000.00.
car2 = Vehicle("Jump","Van","Blue",10000)

# test code
car1.description()
car2.description()


------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~


Related Solutions

Python Create a move function that is only defined in the base class called Objects. The...
Python Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
PYTHON A Class for a Deck of Cards We will create a class called Card whose...
PYTHON A Class for a Deck of Cards We will create a class called Card whose objects we will imagine to be representations of playing cards. Each object of the class will be a particular card such as the '3' of clubs or 'A' of spades. For the private data of the class we will need a card value ('A', '2', '3', ... 'Q', 'K') and a suit (spades, hearts, diamond, clubs). Before we design this class, let's see a...
Create a project called FaceViewer with the following data: FaceComponent class will have: Make a new...
Create a project called FaceViewer with the following data: FaceComponent class will have: Make a new class called FaceComponent that extends JComponent Create a paintComponent method that has a parameter of Graphics type Cast the Graphics variable to Graphics2D Create a circle Face that contains the following: Blue Circle right eye. Green Square left eye. Left & right eye should be same distance from sides of face. Ellipse red nose with the center of the nose being the center of...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama Write a static method in that class called makeLists that takes no parameters and returns no value In makeLists, create an ArrayList object called avengers that can hold String objects. Problem 2 Add the following names to the avengers list, one at a time: Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark Print the avengers object. You will notice that the contents are displayed in...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Using C# create a new grade book program for a teacher. We have a class with...
Using C# create a new grade book program for a teacher. We have a class with 10 students who have each taken 5 tests. Create an array to hold: Each student’s name Each test grade The average for each student's tests Use a random number generator to generate the test scores for each student. The student names may be hard-coded into the array. Create and call a method that calculates and stores each student’s average in the array. Create and...
You are to create a class called ManageDB. The ManageDB class will have a 2 input...
You are to create a class called ManageDB. The ManageDB class will have a 2 input constructor that has the following definition: ManageDB(int number, String fileName) The constructor will create an array of EmployeeDB objects of length "number". The constructor will read the file located at "fileName" and extract the information from that file to populate a database of EmployeeDB objects. The file contains information on the EmployeeDB objects. This information is contained in records. The format of each record...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT