Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Simple program

  Asked By: Bill    Date: Aug 17    Category: Java    Views: 766
  

I am trying to build a simple program that would calculate the fuel
consumption of a car on both normal and rough roads. The car
typically uses 8 liters of fuel per 100 kilometers on normal roads
and 15% more on rough roads. How do I write a program that would
print out the distance the car can travel on a full tank of 40
liters of fuel on both normal and rough roads?

My guess is for rough roads: 100 km / (8 liters + 8 * 0.15)
Also, the kilometers per liter is calculated by 100km/8 liters.

I think my program can only run once with specific result. This is
how I want it. I plan to change the given values to get different
answer.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Adaulfo Fischer     Answered On: Aug 17

That sounds like homework :) Really it isn't that much more advanced
than HelloWorld with a bit of adlibbing (:

Find a HelloWorld tutorial and work up from there :)

 
Answer #2    Answered By: Nicholas Wells     Answered On: Aug 17

Is it okay to declare "rough roads" and "normal roads" as separate
classes?

 
Answer #3    Answered By: Lily Brown     Answered On: Aug 17

It's okay but may not be desirable.

If rough and normal roads have anything in common (i.e. they're both roads) they
would normally be descendents of a common Roads class. However, a normal road
might not be a descendent of a Roads parent, it might just be a Roads object.

But it depends on what the differences are between the two types of roads. If
it's simply an acknowledgement that the rough road is rough, that may just be a
Boolean "rough" attribute of Road (or perhaps an integer scale 1-10 of
"roughness") and not warrant a separate child class at all.

Assuming this is a programming exercise, I'd be tempted to make RoughRoad a
child class of Road and possibly also make NormalRoad a child class of Road, to
experience inheritance as a concept.

 
Didn't find what you were looking for? Find more on Simple program Or get search suggestion and latest updates.




Tagged: