1. Create a constructor function named Car that will accept the following parameters and set them to properties of the same name. (Hint: Use the keyword this ). make model year color 2. Inside the constructor function set the property kmTravelled a value of 0. 3. Create a function on the Car prototype named drive . This function will accept a parameter named distance and inside the function will update the kmTravelled property on our object by adding the passed in value of distance. 4. Add a friendly console message to the drive method displaying the vehicle’s year, make, model and distance travelled. 5. Use the Car constructor function to create a new instance of Car and save it to a variable. Pass it values of a car you own or would like to own. 6. Create another Car object and save it to a variable. Set the values to a car that belongs to a family member or friend. 7. Execute the drive method a few times on your newly created cars (don’t forget to pass a distance). Sample output: The 1969 Ford Mustang has travelled 123km. The 2014 Chevy Cruze has travelled 112km. The 2014 Chevy Cruze has travelled 155km. The 1969 Ford Mustang has travelled 453km. The 1969 Ford Mustang has travelled 698km. The 2014 Chevy Cruze has travelled 598km.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter9: Using Classes And Objects
Section: Chapter Questions
Problem 5E: Create an application named CarDemo that declares at least two Car objects and demonstrates how they...
icon
Related questions
Question

1. Create a constructor function named Car that will accept the following parameters and set them to properties of
the same name. (Hint: Use the keyword this ).
make
model
year
color
2. Inside the constructor function set the property kmTravelled a value of 0.
3. Create a function on the Car prototype named drive . This function will accept a parameter named distance
and inside the function will update the kmTravelled property on our object by adding the passed in value of
distance.
4. Add a friendly console message to the drive method displaying the vehicle’s year, make, model and distance
travelled.
5. Use the Car constructor function to create a new instance of Car and save it to a variable. Pass it values of a car
you own or would like to own.
6. Create another Car object and save it to a variable. Set the values to a car that belongs to a family member or
friend.
7. Execute the drive method a few times on your newly created cars (don’t forget to pass a distance).
Sample output:
The 1969 Ford Mustang has travelled 123km.
The 2014 Chevy Cruze has travelled 112km.
The 2014 Chevy Cruze has travelled 155km.
The 1969 Ford Mustang has travelled 453km.
The 1969 Ford Mustang has travelled 698km.
The 2014 Chevy Cruze has travelled 598km.

Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage