All pastes #260579 Raw Edit

Mine

public text v1 · immutable
#260579 ·published 2006-11-28 14:30 UTC
rendered paste body
import javax.swing.JOptionPane;

public class Question6
{

	public static double calculateCharges(int hr)
	{
		final double initialCharge = 2;
		final double additionalCharge = 0.50; 
		final double maxCharge = 10;
		
		if (hr <= 3)
			return initialCharge;
		else if (hr <= 19)
			return initialCharge + (hr-3) * additionalCharge;
		else
			return maxCharge;
			
	}
	
	public static void main (String[] args)
	{
		int hour = 0;
		double totCharge = 0;
		do
		{
			hour = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter number of hours or 0 to exit:"));
			if (hour != 0)
			{
				System.out.println("The car has been parked for "+hour+" hours\nThe charge is "+calculateCharges(hour));
				totCharge += calculateCharges(hour);
			}
		} while (hour != 0);
		JOptionPane.showMessageDialog(null, "You've earned "+totCharge, "Summary", JOptionPane.INFORMATION_MESSAGE);
	}



        public static  double total () {
        int sum=0;
 
        for(int i=0; i<5; i++) 
            sum=sum+calculateCharges();
 
       JOptionPane.showMessageDialog(null, "Yesterday's running charges is: +sum , JOptionPane.INFORMATION_MESSAGE);
    }
 


}