aspose file tools*
The moose likes Beginning Java and the fly likes Math question (very beginner) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Math question (very beginner)" Watch "Math question (very beginner)" New topic
Author

Math question (very beginner)

Tod Novak
Greenhorn

Joined: Dec 14, 2006
Posts: 13

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!

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

Joined: Dec 31, 2004
Posts: 961
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
Looks correct to me
Tod Novak
Greenhorn

Joined: Dec 14, 2006
Posts: 13

Thank you Edwin!!

That's exactly the nudge I needed.

This is what I added:



And it works like a charm.

Thanks again!

[ May 08, 2008: Message edited by: Tod Novak ]
[ May 08, 2008: Message edited by: Tod Novak ]
 
 
subject: Math question (very beginner)