subject

With the addition of electric cars, we have a need to create a subclass of our Car class. In this exercise, we are going to create the Electric Car subclass so that we can override the miles per gallon calculation since electric cars don’t use gallons of gas. The Car class is complete, but you need to complete the ElectricCar class as outlined in the starter code with comments.
Once complete, use the CarTester to create both a Car and ElectricCar object and test these per the instructions in the CarTester class.
Classes
public class CarTester
{
public static void main(String[] args)
{
// Create a Car object
// Print out the model
// Print out the MPG
// Print the object
// Create an ElectricCar object
// Print out the model
// Print out the MPG
// Print the object
}
}

public class ElectricCar extends Car {
// Complete the constructor
public ElectricCar(String model){
}
// Override the getMPG here.
// It should return: "Electric cars do not calculate MPG.
// Override the toString() here.
// (model) is an electric car.
}

public class Car {
//This code is complete
private String model;
private String mpg;
public Car(String model, String mpg){
this. model = model;
this. mpg = mpg;
}
public String getModel(){
return model;
}
public String getMPG(){
return mpg;
}
public String toString(){
return model + " gets " + mpg + " mpg.";
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:20
1)consider the following code snippet: #ifndef book_h#define book_hconst double max_cost = 1000.0; class book{public: book(); book(double new_cost); void set_cost(double new_cost); double get_cost() const; private: double cost; }; double calculate_terms(book bk); #endifwhich of the following is correct? a)the header file is correct as given.b)the definition of max_cost should be removed since header files should not contain constants.c)the definition of book should be removed since header files should not contain class definitions.d)the body of the calculate_terms function should be added to the header file.
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
The best definition of an idiom is a. a word or phrase that describes a noun b. a word or phrase describing a verb c. a phrase containing figurative language in which the word expresses a different idea from its exact meaning d. a phrase that compares two unlike objects or ideas
Answers: 2
question
Computers and Technology, 24.06.2019 13:30
In the rgb model, which color is formed by combining the constituent colors? a) black b) brown c) yellow d) white e) blue
Answers: 1
question
Computers and Technology, 25.06.2019 02:00
Software and services are used to conceive, plan, and execute projects in any field. these tools are excellent methods of increasing the probability of successful projects. open source linux project management mind-mapping
Answers: 2
You know the right answer?
With the addition of electric cars, we have a need to create a subclass of our Car class. In this ex...
Questions
question
English, 08.01.2020 04:31
question
History, 08.01.2020 04:31
question
Mathematics, 08.01.2020 04:31
Questions on the website: 13722367