import java.util.Scanner; | |
public class ATM { | |
//----------- Constant ----------- | |
public static final int password = 1234; | |
public static final int maxWithdraw = 20000; | |
//----------- Method ----------- | |
public static void welcome() { | |
} | |
public static boolean checkPass(int pass) { | |
return pass == password; | |
} | |
public static boolean checkLimit(int amount) { | |
return amount <= maxWithdraw; | |
} | |
public static boolean check100(int amount) { | |
return amount % 100 == 0; | |
} | |
public static void showBanknotes(int amount) { | |
System.out.println("You need " + amount + " baht"); | |
int numberOfFiftyNotes = amount / 50; | |
amount = amount % 50; | |
int numberOfTwentyNotes = amount / 20; | |
amount = amount % 20; | |
int numberOfTenCoins = amount / 10; | |
//amount = amount / 10; | |
System.out.println(); | |
System.out.println("You get " + numberOfFiftyNotes + " fifty notes"); | |
System.out.println("You get " + numberOfTwentyNotes + " twenty notes"); | |
System.out.println("You get " + numberOfTenCoins + " ten coins"); | |
} | |
public static void goodbye() { | |
System.out.println("Good bye."); | |
} | |
public static void main(String[] args) { | |
System.out.println("-------ATM--------"); | |
welcome(); | |
Scanner keyboard = new Scanner(System.in); | |
System.out.print("Enter 4-digit password: "); | |
int keypass = keyboard.nextInt(); | |
if (checkPass(keypass)) { | |
System.out.print("Enter amount of withdraw: "); | |
int withdraw = keyboard.nextInt(); | |
if (checkLimit(withdraw)) { | |
if (check100(withdraw)) { | |
showBanknotes(withdraw); | |
} else { | |
System.out.println("Sorry. Amount is not divisible by 100"); | |
} | |
} else { | |
System.out.println("Sorry. Under or over withdrawal limit"); | |
} | |
} else { | |
System.out.println("Sorry. Wrong password"); | |
} | |
goodbye(); | |
} | |
} |