Skip to content

Commit 84b66af

Browse files
authored
Update atm.java
Added validation checks for balance less than or equal to zero
1 parent 1e8b2ab commit 84b66af

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

ATM interface/atm.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
//create ATMExample class to implement the ATM functionality
55
public class atm
66
{
7+
public static boolean validateInputAmount(Integer amount)
8+
{
9+
return amount>0;
10+
}
711
//main method starts
812
public static void main(String args[] )
913
{
@@ -30,7 +34,12 @@ public static void main(String args[] )
3034
System.out.print("Enter money to be withdrawn:");
3135

3236
//get the withdrawl money from user
33-
withdraw = sc.nextInt();
37+
withdraw = sc.nextInt();
38+
if(!validateInputAmount(withdraw))
39+
{
40+
System.out.println("Enter amount greater than zero");
41+
break;
42+
}
3443

3544
//check whether the balance is greater than or equal to the withdrawal amount
3645
if(balance >= withdraw)
@@ -53,6 +62,11 @@ public static void main(String args[] )
5362

5463
//get deposite amount from te user
5564
deposit = sc.nextInt();
65+
if(!validateInputAmount(deposit))
66+
{
67+
System.out.println("Enter amount greater than zero");
68+
break;
69+
}
5670

5771
//add the deposit amount to the total balanace
5872
balance = balance + deposit;

0 commit comments

Comments
 (0)