(Java) Q 1,2 ANSWER BOTH PART 1 AND 2!!! Explain the answer step-by-step and include verbal explanation. Thank you!   PART 1: 1. Given the below Car class, write a child class of Car named Tesla. The Tesla class has an additional private boolean variable named autoPilotEnabled. It also has two constructors - a default constructor and a three argument constructor. Both constructors call the appropriate constructors of the parent class. Tesla also has a getter and setter for the autoPilotEnabled variable. Finally, it has a toString method that calls the toString of Car, as well as concatenating the autoPilotEnabled variable.   public class Car { private String make; private String model; public Car() { make = "Make unknown"; model = "Model unknown"; } public Car(String make, String model) { this.make = make; this.model = model; } public String getMake() { return make; } public String getModel() { return model; } public void setMake(String make) { this.make = make; } public void setModel(String model) { this.model = model; } public boolean timeForService(int currMileage) { if (currMileage > 10000) { return true; } return false; } @Override public String toString() { return "Make: " + make + "\nModel: " + model; } }   PART 2: Next, override the timeForService method for the Tesla class to return true if the currMileage is greater than 15000.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 34SA
icon
Related questions
Question

(Java)

Q 1,2

ANSWER BOTH PART 1 AND 2!!!

Explain the answer step-by-step and include verbal explanation. Thank you!

 

PART 1:

1. Given the below Car class, write a child class of Car named Tesla. The Tesla class has an additional private boolean variable named autoPilotEnabled. It also has two constructors - a default constructor and a three argument constructor. Both constructors call the appropriate constructors of the parent class. Tesla also has a getter and setter for the autoPilotEnabled variable. Finally, it has a toString method that calls the toString of Car, as well as concatenating the autoPilotEnabled variable.

 

public class Car {
private String make;
private String model;

public Car() {
make = "Make unknown";
model = "Model unknown";
}

public Car(String make, String model) {
this.make = make;
this.model = model;
}

public String getMake() {
return make;
}

public String getModel() {
return model;
}

public void setMake(String make) {
this.make = make;
}
public void setModel(String model) {
this.model = model;
}

public boolean timeForService(int currMileage) {
if (currMileage > 10000) {
return true;
}
return false;
}

@Override public String toString() {
return "Make: " + make + "\nModel: " + model;
}
}

 

PART 2:

Next, override the timeForService method for the Tesla class to return true if the currMileage is greater than 15000.

Expert Solution
Step 1

I updated the code and also provide the output screenshot and code as per your requirement 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps with 5 images

Blurred answer
Knowledge Booster
Reference Types in Function
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning