programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Liutauras Vilda
• Tim Cooke
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Devaka Cooray
• Ron McLeod
• paul wheaton
Saloon Keepers:
• Tim Moores
• Piet Souris
• Tim Holloway
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Frits Walraven
• Scott Selikoff

# java problem

Greenhorn
Posts: 19
• Number of slices to send:
Optional 'thank-you' note:
Hi!
A parking charge is 2 dollor for up to three houres. After 3 houres the charge increase with 0.5\$ every houre.
if a person parks his car 5.3 houres.
He must pay 2\$ for first 3 houres and 1.5 dollor for every houre 2+1.5=3.5\$

because for 2 hourse we pay 1\$ and for 0,3 houre we should pay 0.5 dollor more.

the above codes result is:
2+(0.5*(5.3-3))=3.15\$
but it must be 3.5\$
because for 2 houres 1\$ and for 0.3 houre 0.5\$ dollor more.

author
Posts: 23928
142
• Number of slices to send:
Optional 'thank-you' note:
You need to round the number of hours up to the next half hour first.

If you already know this, (this was not clear in your question), and just want a suggestion on how to do it. I guess one trick is to double the value, round it up to the nearest whole number with the Math class, and half it back.

Henry

Greenhorn
Posts: 15
• Number of slices to send:
Optional 'thank-you' note:
You can round up the last hour. Round up 0.3 to 1 with Math.ceil();

charge=2+(0.5*(Math.ceil(houre-3)));

Ranch Hand
Posts: 48
• Number of slices to send:
Optional 'thank-you' note:
Sounds like a homework question to me.

 Legend has it that if you rub the right tiny ad, a genie comes out. the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising