Can anyone tell me what I am doing wrong? I can't get it to calculate the charges.

Recommended Answers

All 4 Replies

Can anyone tell me what I am doing wrong? I can't get it to calculate the charges.

what you're doing wrong?
you didn't paste your code in your post

well, maybe he has nothing to post, in which case there's nothing to do the calculation :)

commented: Haha! +5
import java.util.Scanner;

public class Garage {
  public static void openForBusiness() {
    Scanner input = new Scanner(System.in);                                                                         
    int  customerNumber = 1;                                                                                        
    double totalParkingReceipts =0.0;                                                                            
    double parkingCharge;                                                                                           
    double hoursParked;                                                                                             
    String hoursParkedPrompt= "Enter number of hours parked for customer %2d, or <ctrl>z to stop:_";               
    String programOutput= ("\nSummary of Today's Receipts:\n");                                                     
      programOutput += String.format("\n\t%8s   %6s   %7s","Customer","Hours ","Parking");                        
      programOutput += String.format("\n\t%8s   %6s   %7s"," Number ","Parked","  Fee  ");                        
    System.out.println("Task 09-02, Ch06, Programmed by Pam Thomas\n");                                           
    System.out.println("Parking Attendent Activity\n");                                                            
    System.out.printf("\t                                   " + hoursParkedPrompt, customerNumber);                 
      while (input.hasNext()){                                                                                       
        hoursParked=input.nextDouble();                                                                             
            parkingCharge=calculateCharge(hoursParked);                                                               
        totalParkingReceipts += parkingCharge;                                                                      
        programOutput += String.format("\n\t%8d   %6.1f   $%6.2f", customerNumber, hoursParked, parkingCharge);   
        System.out.printf("\tCharge for customer %2d is $%6.2f; "+hoursParkedPrompt, customerNumber, parkingCharge, ++customerNumber);
    } //end while                                                                                                
    programOutput += String.format("\n\t%-17s   $%6.2f","   Total Reciepts", totalParkingReceipts);                
    System.out.println(programOutput);                                                                           
    System.out.println("\nEnd of program");                                                                      
    } // method main
  private static double calculateCharge(double hoursParked) {
    final double minimumParkingCharge= 2.0;                                                                         
    final double maximumParkingCharge= 10.0;                                                                        
    final double maximumParkingHoursForMinimumParkingCharge= 3.0;                                                   
    final double chargePerHourAfterMinimum= 0.5;                                                                    
    double parkingCharge;                                                                                           
    parkingCharge= minimumParkingCharge;                                                                            
      if (hoursParked > maximumParkingHoursForMinimumParkingCharge);                                                
        parkingCharge = minimumParkingCharge + chargePerHourAfterMinimum +  Math.ceil(hoursParked - maximumParkingHoursForMinimumParkingCharge); 
      // End If                                                                                                       
      if (parkingCharge > maximumParkingCharge);                                                                     
        parkingCharge = maximumParkingCharge;                                                                   
        //End IF                                                                                                       
    return parkingCharge;                                                                                          
    } // method calculateCharge
} // class Garage

import java.util.Scanner;
public class GarageTest{
  public static void main(String args[]){
    Garage myGarage=new Garage();                                                                        
    myGarage.openForBusiness();                                                                              
  } //end main
}// end class GarageTest

just a suggestion: use code tags and indentations. might make us actually willing to read the above code.
as far as I can tell, your code is doing exactly what you programmed it to do.
doubt a lot of parking attendants will use it, though, same cost to park for one hour as for parking for a hundred hours? hehe :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.