Skip to content

In this exercise l explore some of the differences between how classes are defined in Java and JavaScript.I revisit the car dealership concept explored in Java and recreate the classes, including their properties and behaviours, using JavaScript.

Notifications You must be signed in to change notification settings

AnaPaulaL27/Lab-Constructors-Prototypes

Repository files navigation

Lab-Constructors-Prototypes- Dealership

Exercise - Constructors & Prototypes

In this exercise we will explore some of the differences between how classes are defined in Java and JavaScript. We're going to revisit the car dealership and recreate the classes, including their properties and behaviours, using JavaScript.

Task -DONE ✅

  • Create a Car class. The car should have properties representing manufacturer, price and engine type. DONE

  • Set up Jest and write tests to make sure you can access each of those properties in a Car object.

  • Create a Dealership class. It should have properties representing its name, maximum number of cars it can have and the cars currently in stock.

  • Add methods to Dealership to:

    • Count the number of cars in stock
    • Add a car to stock
    • Return an array containing each car's manufacturer
    • Find all the cars from a given manufacturer
    • Find the total value of all the cars in stock
  • Write tests for Dealership's methods.

Extensions- DONE ✅

  • Modify and test the method for adding a car to stock to ensure we can't add more cars than we have space for.
  • Add a Customer class with a name, a wallet representing the amount of money they have and a car property which is initialised to be null. Give them a buyCar method which removes a Car from a Dealership and updates their car property. Write tests to ensure all possible conditions are met, eg. the customer can afford the car.
  • Modify the method which searches for cars by manufacturer to let the user search by price or engine type instead.

About

In this exercise l explore some of the differences between how classes are defined in Java and JavaScript.I revisit the car dealership concept explored in Java and recreate the classes, including their properties and behaviours, using JavaScript.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published