9.6.7 Cars Github |link|
objects. The program should prompt the user to input car details until "exit" is typed, then print a summary of all cars entered. 1. Set up the Car and ElectricCar Classes
// In ElectricCar.java public class ElectricCar extends Car public ElectricCar ( String model , int batteryLevel ) super ( model , batteryLevel ); // Overriding toString to match requirements @ Override public String toString () return getModel() + " electric car" ; Use code with caution. Copied to clipboard 4. Sample Output 9.6.7 cars github
If you are looking for a specific line of code or a file named objects
Create an ArrayList cars = new ArrayList (); to store objects of both types. Logic: Ask if the car is electric ( y/n ). Prompt for the model and fuel/battery percentage. Set up the Car and ElectricCar Classes // In ElectricCar