Results 1 to 4 of 4
  1. #1
    gard007 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default 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. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default 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. #3
    gard007 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default 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. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

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

    You're welcome.

Similar Threads

  1. totally stumped -- java applet with buttons
    By babyruth1193 in forum Java Applets
    Replies: 2
    Last Post: 11-30-2011, 09:41 AM
  2. Help with this java code? help appreciated
    By jordan123 in forum New To Java
    Replies: 2
    Last Post: 11-06-2011, 07:06 PM
  3. Java need help! Help will be very much appreciated
    By paccerz in forum New To Java
    Replies: 1
    Last Post: 08-23-2011, 09:47 PM
  4. Replies: 10
    Last Post: 01-17-2011, 11:41 PM
  5. stumped......
    By trueblue in forum New To Java
    Replies: 21
    Last Post: 07-13-2009, 05:16 PM

Posting Permissions

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