Hi Dw
I'm creating an atm appication and now my research pointed me to use the Java Point Of Service/Sale (JPOS) my application allow user to choose the amount from the options displayed on the screen and the user will use the number keypad to make his/her selection and the amount displayed on screen is retrieved from his/her account and it is splited in to 5 ways. Now if I run it, it gives me 5 errors under the Dispense amount, I've commented next to the line(s) where there are errors and I've wrote the error that I get as is on the comment in the codes.Please refer to the codes below.
/*
*@author Mr Hacker
*/
import java.util.Scanner;
import CashDispenser;
public class Main {
private double currentBal =1899562589;
Scanner input = new Scanner(System.in);
private CashDispenser cashDispenser;
int amount;
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(" Thank you for using This ATM today. Bye!");
}
}
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] - R10");
System.out.println("[2] - R20");
System.out.println("[3] - R50");
System.out.println("[4] - R100");
System.out.println("[5] - R200");
System.out.println("[6] - MAIN MENU");
System.out.print("Please select your option now: ");
withdrawSelection =input.nextInt();
boolean cashDispensed = false; // cash was not dispensed yet
// Here I'm trying to dispense the choosen amount out of the device.
switch (withdrawSelection){
case 1:
accountWithdraw(10);
amount = (10);
CashDispenser.dispenseCash(amount); // My error starts here it says 'non-static method dispenseCash(int) cannot be referenced from a static context'
cashDispensed = true;
// BillDispenser.dispenseCash(10);
// BillDispenser =(10);
// BillDispenser.dispenseCash();
mainMenu();
break;
case 2:
accountWithdraw(20);
amount = (20);
CashDispenser.dispenseCash(amount); // same error here
cashDispensed = true;
// BillDispenser =(20);
// BillDispenser.dispenseCash(20);
mainMenu();
break;
case 3:
accountWithdraw(50);
amount = (50);
CashDispenser.dispenseCash(amount); // same error here
cashDispensed = true;
// BillDispenser =(50);
// BillDispenser.dispenseCash();
mainMenu();
break;
case 4:
accountWithdraw(100);
amount = (100);
CashDispenser.dispenseCash(amount); // same error here
cashDispensed = true;
// BillDispenser =(100);
// BillDispenser.dispenseCash();
mainMenu();
break;
case 5:
accountWithdraw(200);
amount = (200);
CashDispenser.dispenseCash(amount); // Error ends here.
cashDispensed = true;
// BillDispenser =(200);
// BillDispenser.dispenseCash();
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] - R20");
System.out.println("[2] - R50");
System.out.println("[3] - R100");
System.out.println("[4] - R200");
System.out.println("[5] - MAIN MENU");
System.out.print("Please select your option now: ");
addSelection =input.nextInt();
switch (addSelection){
case 1:
accountAdd(20);
mainMenu();
break;
case 2:
accountAdd(50);
mainMenu();
break;
case 3:
accountAdd(100);
mainMenu();
break;
case 4:
accountAdd(200);
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
}
}