Advanced Placement (AP)
Advanced Placement (AP), 23.12.2020 14:00, Lilyy1k

Can someone help? You are going to create a Car class to simulate how far a car can drive on a road trip. To do this, you will need to complete both the Car and the CarTester classes.

For the Car class, you will use the following variables and methods:

Instance Variables:

private double efficiency // this is miles per gallon
private double gas
private double tankCapacity
private double totalMilesDriven
Constructor:

public Car(double carEfficiency, double carTankCapacity)
Methods:

* public void addGas()- this method should fill the car with gas up to the tank capacity. The method should print `Filling up ...`

* public void addGas(double amount) - This should add amount to the tank. If the amount is greater than the capacity, set the gas to the tank capacity. The method should print `Adding gas ...`

* public double getTotalMilesDriven() - returns the number of miles the car has driven

* public void drive(double distance) - checks if car can drive that number of miles, and then adds miles to totalMilesDriven and subtracts the amount of gas needed to go those miles. The method should print `Driving [distance]` or, if the distance is too far, it should print `Can't drive [distance]. That's too far!`

* public boolean canDrive (double distance) - returns true if the car has gas

* public double milesAvailable() - returns how many more miles the car could drive

* public double getGas() - returns the amount of gas left
In creating both the Car and CarTester, be sure to check the sample output to guide your design considerations. You will need to have a conditional statement in the drive method to determine if you can drive the correct distance.

Also, make sure you check that you don’t over fill the gas tank!

Sample Output:
Filling up ...
Miles available: 300.0
Driving 100.0
Miles available: 200.0
Adding gas ...
Miles available: 260.0
Can't drive 1000.0. That's too far!
Driving 200.0
Gas remaining: 3.0
Total Miles Driven: 300.0

answer
Answers: 2

Other questions on the subject: Advanced Placement (AP)

image
Advanced Placement (AP), 23.06.2019 02:30, Kcloughley
Daryl wouod like to open new checkings and savings accounts one pf his primary concerns is avoiding bank fees
Answers: 2
image
Advanced Placement (AP), 23.06.2019 16:40, shjsmbee8177
Which statement is true? a crt is a higher-level respiratory therapy certification. every crt is also an rrt a rrt is a certification that adds a specialization every rrt is also a crt
Answers: 1
image
Advanced Placement (AP), 24.06.2019 11:30, vjmfghhh
Pleas give me brief explanation about deterministic model in advanced hydrology
Answers: 1
image
Advanced Placement (AP), 25.06.2019 15:00, iamsecond235p318rq
Ahypothesis test is conducted with a significance level of 5%. the alternative hypothesis states that more than 65% of a population is right-handed. the p-value for the test is calculated to be 0.03. which of the following statements is correct? we can conclude that more than 3% of the population is right-handed. we cannot conclude that more than 65% of the population is right-handed. we can conclude that more than 65% of the population is right-handed. we can conclude that exactly 3% of the population is right-handed. there is not enough information given to make a conclusion.
Answers: 2
Do you know the correct answer?
Can someone help? You are going to create a Car class to simulate how far a car can drive on a road...

Questions in other subjects:

Konu
Mathematics, 14.01.2020 18:31