File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44//create ATMExample class to implement the ATM functionality
55public 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 ;
You can’t perform that action at this time.
0 commit comments