Skip to content

Commit 27829a4

Browse files
committed
add a comment explaining the ternary operator in Car class
1 parent 67ddaae commit 27829a4

File tree

1 file changed

+6
-0
lines changed
  • src/org/launchcode/java/demos/testing/main

1 file changed

+6
-0
lines changed

src/org/launchcode/java/demos/testing/main/Car.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public void drive(double miles)
7676
{
7777
//adjust fuel based on mpg and miles requested to drive
7878
double maxDistance = this.milesPerGallon * this.gasTankLevel;
79+
/**the double below uses some syntax called the ternary operator.
80+
* if the value of miles is greater than the value of maxDistance,
81+
* then milesAbleToTravel = maxDistance.
82+
* otherwise, if miles is not greater than maxDistance,
83+
* then milesAbleToTravel = miles
84+
*/
7985
double milesAbleToTravel = miles > maxDistance ? maxDistance : miles;
8086
double gallonsUsed = milesAbleToTravel / this.milesPerGallon;
8187
this.gasTankLevel = this.gasTankLevel - gallonsUsed;

0 commit comments

Comments
 (0)