Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Trying to calculate hours by the hour

1. ## Trying to calculate hours by the hour

Hidy ho all, I have a homework assignment where I have to calculate the amount of hours someone parked in a parking lot.

For every hour (or part of an hour) parked greater then 2 I need to charge them a bit more.

now I can do that math easily enough. trouble is, I don't know if its possible to round up a double.

my code has to involve a class. And, I think I know how to do that. My trouble is, I don't know how to round up doubles. Can you round up doubles?

2. ## Re: Trying to calculate hours by the hour

Look at the Math class. It has some useful methods.
Also rounding can be done by adding 0.5 and casting to an int.

3. ## Re: Trying to calculate hours by the hour

ok, so I have to take the amount of hours. And if they parked more then 3 hours, then add 50 cents on top of the flat rate to begin with. so if they parked 3.1 hours I need charge then 3.50.

My math will be, if hours parked < 3 just charge them 2.00. If the hours parked > 3 and < 22 then minus 3, and then multiply the remainder (whatever that remainder is) by .5. what I need is to take something like .1-.4 and turn it into a whole number of 1 for this to work. The java.math.* library can do this?

Also, I'm messing around with array lists in this program for the first time. I created a class called calcuateCharges (thats what the instructions say to call it) that stores a persons first name, last name, hours parked and the total to charge them. The above math is in that total figuring part.

So far, when I compile this program I'm getting no errors. So, I'm fairly certain the syntax is right up to this point.
Heres what I put:
`ArrayList<calculateCharges> Customers = new ArrayList<>();`
. I'd like to use a for loop to store parts of the customers in, while using a control variable to determine how many times the for loop runs. My question is, how to get access to individual parts of the array list?

4. ## Re: Trying to calculate hours by the hour

You can try Math.ceil() method.