Question
This is a question for my assignment, please respond with the correct code as soon as you can. To be done on Java. Will upvote
This is a question for my assignment, please respond with the correct code as soon as you can. To be done on Java. Will upvote definitely, thanks!
/** A class suitable for the simulating a car driving. */ public class Car implements Comparable
/** Initializes a car with a given fuel efficiency @param fuelEfficiency the default fuel efficiency */ public Car(String name, double fuelEfficiency) { this.name = name; this.fuelEfficiency = fuelEfficiency; gasLevel = 0; }
/** Puts gas in the tank. @param gas amount of gas to add */ public void addGas(double gas) { this.gasLevel = gasLevel + gas; }
/** Simulates driving the car and thus reducing the gas in the tank @param distance miles driven */ public void drive(double distance) { gasLevel -= distance * fuelEfficiency; }
/** Returns the current gas level. @return current gas level */ public double getGasLevel() { return gasLevel; } //-----------Start below here. To do: approximate lines of code = 4 // write a method to implement the Comparable interface // The method should compare two cars based on fuel efficiency (higher fuel efficiency is better) //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. public String toString() { return "Name: " + name + " Gas Level: " + gasLevel + " FuelEfficiency: " + fuelEfficiency; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started