6 Years
Discussion Span
Last Post by stultuske
Featured 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

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()){                                                                                       
        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("\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();                                                                        
  } //end main
}// end class GarageTest

Edited by mike_2000_17: Fixed formatting


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 :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.