# Math question (very beginner)

posted 7 years ago

- 0

I'm very new to Java (and programming in general) and am working on a series of tutorials.

The problem is...I'm not so good at the math parts. If anyone could just point me in the right direction on how to solve this problem, it would be greatly appreciated.

---Taken from the tutorial---

Exercise 3 --- Last Chance Gas

Al's Last Chance Gas station sits on Route 190 on the edge of Death Valley. There is no other gas station for 200 miles. You are to write a program to help drivers decide if they need gas. The program asks for:

The capacity of the gas tank, in gallons.

The indication of the gas gauge in percent (full= 100, three quarters full = 75, and so on).

The miles per gallon of the car.

The program then writes out "Get Gas" or "Safe to Proceed" depending on if the car can cross the 200 miles with the gas remaining in the tank.

Tank capacity:

12

Gage reading:

50

Miles per gallon:

30

Get Gas!

This is what I've come up with so far:

I have to use only integers for the arithmetic and can only use if-else statements.

Thank You,

[ May 08, 2008: Message edited by: Tod Novak ]

The problem is...I'm not so good at the math parts. If anyone could just point me in the right direction on how to solve this problem, it would be greatly appreciated.

---Taken from the tutorial---

Exercise 3 --- Last Chance Gas

Al's Last Chance Gas station sits on Route 190 on the edge of Death Valley. There is no other gas station for 200 miles. You are to write a program to help drivers decide if they need gas. The program asks for:

The capacity of the gas tank, in gallons.

The indication of the gas gauge in percent (full= 100, three quarters full = 75, and so on).

The miles per gallon of the car.

The program then writes out "Get Gas" or "Safe to Proceed" depending on if the car can cross the 200 miles with the gas remaining in the tank.

Tank capacity:

12

Gage reading:

50

Miles per gallon:

30

Get Gas!

**Use integers for all input and all arithmetic.**This is what I've come up with so far:

I have to use only integers for the arithmetic and can only use if-else statements.

Thank You,

[ May 08, 2008: Message edited by: Tod Novak ]

"-Of all the things I've lost...I miss my mind the most!"

Edwin Dalorzo

Ranch Hand

Posts: 961

posted 7 years ago

- 0

Well, you will need first to find out how many gallons you actually have. You said the gauge reading is a percentage.

So, the current gallons formula must be somewhat like this:

Then you will need to determine how far your current gallons can take you.

If maximumDistance is smaller than 200, then it is time to get gas.

Also, you could avoid all this calculations by determining, at the begining, if the car's tank capacity and miles per gallon can actually take the driver that far.

Somewhat like this

I hope I am not wrong on these calculations. I am not very good at math myself.

I hope that helps.

So, the current gallons formula must be somewhat like this:

Then you will need to determine how far your current gallons can take you.

If maximumDistance is smaller than 200, then it is time to get gas.

Also, you could avoid all this calculations by determining, at the begining, if the car's tank capacity and miles per gallon can actually take the driver that far.

Somewhat like this

I hope I am not wrong on these calculations. I am not very good at math myself.

I hope that helps.

I agree. Here's the link: http://aspose.com/file-tools |