Hello please do not paste the answer that is already
visible on answers, i'm looking for an alternative
approach
I'm also wondering how to implement a way to make sure that the
drive() method cannot be called with a distance that consumes more
than the available fuel
Thank you
Create a new C# Console Application project and add a class called Car with the following parameters, which you will set in the constructor: - the fuel efficiency which is measured in miles per gallon (mpg); – the fuel in the tank (in litres) with an initial value of 0; - the total miles driven with an initial value of 0. Set up a constant to hold the current cost of fuel in dollars per litre. For the purpose of this program, the cost per litre of petrol is 1.385$. You must implement the following methods in the Car class: - getFuel - this accessor method should return the amount of fuel in the tank - getTotalMiles – this accessor method should return the total miles the car has driven - setTotalMiles - this mutator method should update the total miles the car has driven - printFuelCost -a method that returns the cost of fuel in dollars and cents. - addFuel - this method should add fuel to the tank and calculate the cost of the fill - calcCost - this method will take the amount of fuel, in litres, and multiply it by the cost of fuel (in dollars per litre) convertToLitres - this method should accept a parameter for the number of gallons, convert that value to litres and return the value in litres. This can be done by multiplying the value by 4.546. - drive - this method should simulate driving the car for a certain distance in miles. It will accept the number of miles driven and update the total miles stored for the car. Then you will need to calculate the fuel used by dividing the distance driven by mpg. This will return the number of gallons used, which you then need to convert into litres. The method should display a message to state the total cost of the journey, in dollars and cents. For the purposes of this class, you can assume that the drive() method is never called with a distance that consumes more than the available fuel.
Hello please do not paste the answer that is already visible on answers, i'm looking for an alternative approach I'm also
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am