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.
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 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...
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...
Create a new class called Account with a main method that contains the following: • A...
Create a new class called Account with a main method that contains the following: • A static variable called numAccounts, initialized to 0. • A constructor method that will add 1 to the numAccounts variable each time a new Account object is created. • A static method called getNumAccounts(). It should return numAccounts. Test the functionality in the main method of Account by creating a few Account objects, then print out the number of accounts
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class called aDLLNode. class aDLLNode { aDLLNode prev;    char data;    aDLLNode next; aDLLNode(char mydata) { // Constructor data = mydata; next = null;    prev = null;    } }; Step 3: In the main() function of the driver class (Lab5.5), instantiate an object of type aDLLNode and print the content of its class public static void main(String[] args) { System.out.println("-----------------------------------------");    System.out.println("--------Create...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public final class Account implements Comparable {     private String firstName;     private String lastName;     private int accountNumber;     private double balance;     private boolean isNewAccount;     public Account(             String firstName,             String lastName,             int accountNumber,             double balance,             boolean isNewAccount     ) {         this.firstName = firstName;         this.lastName = lastName;         this.accountNumber = accountNumber;         this.balance = balance;         this.isNewAccount = isNewAccount;     }     /**      * TO DO: override equals      */     @Override     public boolean equals(Object other) {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT