Computers and Technology

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.";
}
}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 09:00, vetterk1400
Design a class tictactoe that: holds the following information about the game: two-dimensional array (3 by 3), and winner. add additional variables as needed. includes the functions to perform the various operations on objects. for example, function to print the board, getting the move, checking if move is valid, determining if there is a winner after each move. add additional operations as needed. includes constructor(s). write the functions of the class, and write a program that uses the class. the program should declare an object of type tictactoe. the program will create the board and store it in the array. the program will allow two players to play the tic-tac-toe game. after every valid move update the array, check if there is a winner. if there is no winner and no tie, then print the board again to continue.
Answers: 2
image
Computers and Technology, 23.06.2019 09:30, nsjcbdhcb
Light travels at a speed of 186,000 miles a second. the distance light travels in a year is 5,865,690,000,000 miles/year 5,865,695,000,000 miles/year 58,656,950,000,000 miles/year 6,789,000,0000 miles/year
Answers: 1
image
Computers and Technology, 24.06.2019 02:10, ttangelique
Which sentences describe the things you need to ensure while creating a sketch and a drawing? while an artistic or creative drawing is a creative expression, a technical drawing is an informative expression. you need to create accurate and neat drawings to convey accurate information. a technical drawing clearly conveys its meaning or information, and does not leave room for interpretation maintain a good speed while creating drawings
Answers: 1
image
Computers and Technology, 24.06.2019 07:00, Dkhaurithompson
Selective is defined as paying attention to messages that are consistent with one’s attitudes and beliefs and ignoring messages that are inconsistent.
Answers: 1
Do you know the correct answer?
With the addition of electric cars, we have a need to create a subclass of our Car class. In this ex...

Questions in other subjects: