codechef program #2 :ATM


PROBLEM STATEMENT:

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.

MY SOLUTION:

 import java.util.Scanner;



/**
 *
 * @author lol ik */
public class ATM {
   
  
    public static void main(String [] args)
    { //  ATM obj=new ATM();
        Scanner in=new Scanner(System.in);
       // System.out.println("Enter the amount you want to deposit");
        int a=in.nextInt();
       // System.out.println("Enter the intial amount");
        double c=in.nextDouble();
        if(c>0&&a>0&&c<=2000&&a<=2000)
        {
            String e = String.format("%.2f", c);
      
        double f=c-0.50;
        double h=f-a;
        String j = String.format("%.2f", h);
        if(c>=(a+0.50)&&a%5==0)
        {
            System.out.println(j);
        }
        else if(c>(a+0.50)&&a%5!=0)
        {
          System.out.println(e);  
        }
        else
        {
             System.out.println(e);
        }
    }
        else{
            System.out.println(c);
        }
}
}
  Posted by lol ik

Comments

Popular Posts