Knowee
Questions
Features
Study Tools

Import Car from 10-car.js.Implement a class named EVCar that extends the Car class:Constructor attributes:brand (String)motor (String)color (String)range (String)Each attribute must be stored in an “underscore” attribute version (ex: name is stored in _name)For privacy reasons, when cloneCar is called on a EVCar object, the object returned should be an instance of Car instead of EVCar.

Question

Import Car from 10-car.js.Implement a class named EVCar that extends the Car class:Constructor attributes:brand (String)motor (String)color (String)range (String)Each attribute must be stored in an “underscore” attribute version (ex: name is stored in _name)For privacy reasons, when cloneCar is called on a EVCar object, the object returned should be an instance of Car instead of EVCar.

🧐 Not the exact question you are looking for?Go ask a question

Solution

  1. Primero, importa la clase Car desde el archivo 10-car.js:
import Car from './10-car.js';
  1. Implementa la clase EVCar que extiende la clase Car:
class EVCar extends Car {
  constructor(brand, motor, color, range) {
    super(brand, motor, color);
    this._range = range;
  }

  cloneCar() {
    return new Car(this._brand, this._motor, this._color);
  }
}
  1. Asegúrate de que cada atributo se almacene en una versión con guion bajo:
class EVCar extends Car {
  constructor(brand, motor, color, range) {
    super(brand, motor, color);
    this._brand = brand;
    this._motor = motor;
    this._color = color;
    this._range = range;
  }

  cloneCar() {
    return new Car(this._brand, this._motor, this._color);
  }
}
  1. La función cloneCar debe devolver una instancia de Car en lugar de EVCar:
class EVCar extends Car {
  constructor(brand, motor, color, range) {
    super(brand, motor, color);
    this._brand = brand;
    this._motor = motor;
    this._color = color;
    this._range = range;
  }

  cloneCar() {
    return new Car(this._brand, this._motor, this._color);
  }
}
  1. Finalmente, exporta la clase EVCar si es necesario:
export default EVCar;

El código completo sería:

import Car from './10-car.js';

class EVCar extends Car {
  constructor(brand, motor, color, range) {
    super(brand, motor, color);
    this._brand = brand;
    this._motor = motor;
    this._color = color;
    this._range = range;
  }

  cloneCar() {
    return new Car(this._brand, this._motor, this._color);
  }
}

export default EVCar;

This problem has been solved

Similar Questions

Refer to the video lecture about naming conventions. Which is the most accurate naming convention for organizing various vehicles (cars, vans, trains, planes, etc...) by color, where the vehicle type is the data object type and the color is an attribute.Blue_CarCar_LargeGreen_SedanCar_Blue

Write the codeCreate a Python program to model vehicles, specifically two types: Car and Truck.Begin by defining a base class Vehicle with attributes make, model, and price. Subsequently, create two derived classes, Car and Truck, both of which inherit from the Vehicle class. Each derived class should introduce its unique attributes, and:Implement a method display_info in the base class Vehicle to print the common attributes (make, model, price).Override the display_info method in each derived class (Car and Truck) to print the make, model, price along with the unique attributes (num_doors for Car and max_load for Truck) respectively.Input Format:For Car:The first line contains the make, model, price, and number of doors of the car, separated by spaces.For Truck:The first line contains the make, model, price, and maximum load capacity of the truck, separated by spaces.Output Format:The first line should display information about the car, including the make, model, price, and number of doors.The second line should display information about the truck, including the make, model, price, and maximum load capacity.Sample Test CasesTest Case 1:Expected Output:Enter·make,·model,·price,·and·number·of·doors·of·the·car·(separated·by·spaces):·Honda civic 500000 5Enter·make,·model,·price,·and·maximum·load·capacity·of·the·truck·(separated·by·spaces):·Tesla hammer1002 1200000 7000Honda·civic·$500000Number·of·doors:·5Tesla·hammer1002·$1200000Maximum·load·capacity:·7000·tons

Complete the Car class byDeclaring the String factory instance variableDeclaring the String model instance variableDeclaring int year instance variableDeclaring string colour instance variableWriting the constructor method with input parameters for factory, model, year and colourWriting the method carAge to display the age of the car (2024 - year)Complete the main method byUsing new to create an instance of Car with the constructor: Car("BMW" , "X5" , 2021 , "Black") Printing the car detailsPrinting the return value for the carAge() method on the Car instance

//Creating a constructor function   function Vehicle()  {      this.vehicleName="vehicleName";      throw new Error("You cannot create an instance of Abstract Class");  }  Vehicle.prototype.display=function()  {      return "Vehicle is: "+this.vehicleName;  }  //Creating a constructor function  function Bike(vehicleName)  {      this.vehicleName=vehicleName;  }  //Creating object without using the function constructor  Bike.prototype=Object.create(Vehicle.prototype);  var bike=new Bike("Honda");  document.writeln(bike.display());       </script>

Create two (2) classes named Car and TestCar.In the Car class, initialize two (2) public static variables: MAKE (String, final) and numCars (int). Set their values to "Toyota" and 0, respectively.Declare two (2) empty String instance variables named chassisNo and model.Create a public constructor with a single parameter named model (String).  This constructor should:Increment the value of numCars by one.Set the value of chassisNo based on the result of concatenating the String "ch" and the value of numCars. Syntax: chassisNo = ch + numCars;Use the this keyword to set the instance variable model equal to the value of the parameter model.Display a message saying "Car manufactured".Create two (2) pairs of getter and setter methods that will allow you to get and set the values of the two (2) instance variables: getModel() and setModel(), getChassisNo() and setChassisNo()Add a public toString() method that will return and display the car's make, model, and chassis number in separate lines.In the main method of the TestCar class, display the car's make and the initial number of manufactured cars by accessing them from the Cars class. Example: System.out.println("Manufacturer: " + Car.MAKE);Instantiate two (2) Car objects assigning the values "Camry" and "Veloz", respectively. Example: Car car1 = new Car("Camry");Add two (2) statements to display the data of the two (2) Car objects. Example: System.out.println(car1);Display the total number of cars manufactured by accessing the numCars method.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.