File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math question (very beginner)

 
Tod Novak
Greenhorn
Posts: 13
MySQL Database PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks correct to me
 
Tod Novak
Greenhorn
Posts: 13
MySQL Database PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic