# Thread: Stumped... any help would be appreciated!

1. Member
Join Date
Nov 2011
Posts
2
Rep Power
0

## Stumped... any help would be appreciated!

My challenge is to generate a parking garage program. The guidelines: There is a \$2 minimum fee to park for up to 3 hours. The garage charges an extra \$1.00 for any time over 3.0 hours (or part thereof) for extra time (i.e. 3.5 hours would cost a total of 2.50 because the .5 - the hours over is multiplied by the 1.00) The maximum charge for any given 24 hour period is \$10. Assume that no car will park for longer than 24 hours.

I guess the part that I'm getting lost on is the or part thereof

Here's what I've got:

Java Code:
``` import java.util.Scanner;

public class ParkingGarage
{

public void startCharging()
{ //calculate charges

Scanner input = new Scanner( System.in );

double totalReceipts = 0.0; // total charges collected for the day
double fee; // the charge for the current customer
double hours; // hours for the current customer

System.out.print("Enter number of hours parked (enter a negative to quit): " ); //customers hours requested
hours = input.nextDouble();

while ( hours >= 0.0 )
{ //begin loop for customer input

fee = calculateCharges( hours );
totalReceipts += fee;

System.out.printf( "Current Charge: \$%.2f, Total Charges: \$%.2f\n", fee, totalReceipts );

System.out.print( "Enter number of hours parked (enter a negative to quit): " );
hours = input.nextDouble();
} // end while loop

} // end method startCharging

public static double calculateCharges( double hours )
{ //method to calculate charges (2nd method per instruction)

double charge = 2.0; //minimum charge

if (hours > 3.0 )
charge = 2.0 + 1.0 * Math.ceil( hours - 3.0); // charges for exceeding 3 hours

if ( charge > 10.0 ) // maximum alloted charge
charge = 10.0;

return charge; //returns final charge based on 'if' calculations above

} // end method calculateCharges

} // end class ParkingGarage```
and to test:

Java Code:
```
public class ParkingGarageTest
{

public static void main( String args[] )
{ //main method

ParkingGarage application = new ParkingGarage();
application.startCharging();

} //end main method

} //end class GarageTest```
When I input, for instance, 4.5 as my hours- I'm not getting the proper answer. It's giving me \$4.00...

I appreciate any tips.

-Frustrated.

2. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14

## Re: Stumped... any help would be appreciated!

When I input, for instance, 4.5 as my hours- I'm not getting the proper answer. It's giving me \$4.00...
What should the proper answer be, and how did you calculate that? What role did finding the ceiling of a value play in your calculation?

3. Member
Join Date
Nov 2011
Posts
2
Rep Power
0

## Re: Stumped... any help would be appreciated!

I am such a goober.

The proper answer is 3.50 based on the guidelines (1.5 * \$1.00 + base of \$2.00). I've got it working... thank you for pointing out the math.ceil aspect.

4. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14

## Re: Stumped... any help would be appreciated!

You're welcome.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•