Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 { private String name; private double fuelEfficiency; private double gasLevel;

/** 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions