Hi DW
I'm creating an ATM program and now I want to call the Dispensor to dispense the selected amount from the options provided. The main problem here is importing this import atm.input.CashDispenser;
the rest of the code is fine. here is the full code:
import atm.input.CashDispenser;
import java.util.Scanner;
public class Main {
private double currentBal =1899562589;
Scanner input = new Scanner(System.in);
public void mainMenu(){
int selection;
System.out.print("Welcome to the Automated Teller Machine!\n");
System.out.println("Select from the following menu options below:\n");
System.out.println("========================");
System.out.println("| [1] Check Balance |");
System.out.println("| [2] Withdrawal |");
System.out.println("| [3] Deposit |");
System.out.println("| [4] Exit |");
System.out.println("========================");
System.out.print("Please select your option now: ");
selection =input.nextInt();
switch (selection){
case 1:
viewBalance();
break;
case 2:
withdrawFunds();
break;
case 3:
depositFunds();
break;
case 4:
System.out.println(" Goodbye! ");
}
}
public void viewBalance() {
int selection1;
System.out.println("You have selected Balance.\n");
System.out.println("\t-- Your Current Balance is:R " + currentBal);
System.out.println("Return to main menu? \n [1] for YES \n");
selection1 =input.nextInt();
switch (selection1){
case 1:
mainMenu();
break;
}
}
public void withdrawFunds() {
int withdrawSelection;
System.out.println("Amount to withdraw: ");
System.out.println("[1] - R1500");
System.out.println("[2] - R3500");
System.out.println("[3] - R5000");
System.out.println("[4] - R10000");
System.out.println("[5] - R20000");
System.out.println("[6] - MAIN MENU");
System.out.print("Please select your option now: ");
withdrawSelection =input.nextInt();
switch (withdrawSelection){
case 1:
accountWithdraw(1500);
mainMenu();
break;
case 2:
accountWithdraw(3500);
mainMenu();
break;
case 3:
accountWithdraw(5000);
mainMenu();
break;
case 4:
accountWithdraw(10000);
mainMenu();
break;
case 5:
accountWithdraw(20000);
mainMenu();
break;
case 6:
mainMenu();
break;
}
}
public void accountWithdraw(int withdrawFunds){
currentBal = currentBal -withdrawFunds;
System.out.println("Please take your funds.");
}
public void depositFunds(){
int addSelection;
System.out.println("Amount to deposit: ");
System.out.println("[1] - R1500");
System.out.println("[2] - R3500");
System.out.println("[3] - R5000");
System.out.println("[4] - R20000");
System.out.println("[5] - MAIN MENU");
System.out.print("Please select your option now: ");
addSelection =input.nextInt();
switch (addSelection){
case 1:
accountAdd(1500);
mainMenu();
break;
case 2:
accountAdd(3500);
mainMenu();
break;
case 3:
accountAdd(5000);
mainMenu();
break;
case 4:
accountAdd(20000);
mainMenu();
break;
case 5:
mainMenu();
break;
}
}
public void accountAdd (int depositFunds){
currentBal = currentBal +depositFunds;
System.out.println("Thank you.");
}
public static void main(String[] args) {
new Main().mainMenu(); //creating the instance and calling the method
}
}