This is the question:
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja’s account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja’s account balance after an attempted transaction.
Input
Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.
Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja’s initial account balance.
Output
Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.
This is my code:
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws Exception
{
try{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int debit;
double bal=0.00;
debit=Integer.parseInt(in.readLine());
bal=Double.parseDouble(in.readLine());
if(debit>0 && bal>=0 && debit<=2000 && bal<=2000){
if(debit>bal)
System.out.println(String.format("%.2f", bal));
else if(debit%5!=0)
System.out.println(String.format("%.2f", bal));
else{
bal-=debit;
bal=bal-0.50;
System.out.println(String.format("%.2f", bal));
}
}
else System.exit(0);
}
catch(Exception e){
return;
}
}
}