I am still very new to Java. For class, I was to create an object-oriented simple ATM that offers a menu with a choice of four actions: Deposit money, withdrawal money, view balance, and exit. I have an account class and a user class. I was able to figure out hour to do all of that and run my ATM with no errors. Keep in mind, this is a simple ATM, one user, no account number or PIN, and I started him off with 5g's. I want to get ahead, so for the next assignment I need to allow up to max(25) bank accounts to be accessed by the user. The data for the bank accounts will be stored in arrays. We need a bank account object, a bank object containing the array, and a user object. The program will be menu driven.
Any help would be appreciated. Thanks in advance :) here is what I have so far.
Account
import java.util.Scanner;
public class ATMacct {
double Bal = 5000.0;
Scanner scannerObject = new Scanner(System.in);
void makeDeposit(){
System.out.print( "Please, enter amount to deposit $");
double lDep;
lDep = scannerObject.nextDouble();
Bal = Bal + lDep;
System.out.println( " You have depsited $" + lDep);
System.out.println( " Your new balance is $" + Bal);
}
void makeWithdrawal(){
System.out.print( "Please, enter amount to withdraw $");
double lWDraw;
lWDraw = scannerObject.nextDouble();
if (lWDraw <= Bal){
Bal = Bal - lWDraw;
System.out.println( "You have withdrawn $" + lWDraw);
System.out.println( "Your new balance is $" + Bal);
}else{
System.out.println("Insufficient funds!");
}
}
void dispBal(){
System.out.println( "Your current balance is $" + Bal);
}
}
User
import java.util.Scanner;
public class ATMuser
{
public static void main(String[] args)
{
ATMacct myAcct = new ATMacct();
int Choice;
do{
dispMenu();
Choice = getChoice();
proChoice(Choice, myAcct);
}
while (Choice !=0);
}
static void dispMenu()
{
System.out.println( "|==================================|");
System.out.println( "| TONY'S FIRST NATIONAL BANK |");
System.out.println( "|***********Menu Options***********|");
System.out.println( "|__________________________________|");
System.out.println( "| Press 1 To Make Withdrawal |");
System.out.println( "| Press 2 To Make Deposit |");
System.out.println( "| Press 3 To View Current Balance |");
System.out.println( "| Press 0 To Exit |");
System.out.println( "|__________________________________|");
System.out.println( "| Please Make Selection Now... |");
System.out.println( "|==================================|");
}
static int getChoice()
{
Scanner scannerObject = new Scanner(System.in);
int pChoice, Choice;
pChoice = scannerObject.nextInt();
Choice = pChoice;
return Choice;
}
static void proChoice(int Choice, ATMacct myAcct)
{
switch (Choice)
{
case 1: myAcct.makeWithdrawal();
break;
case 2: myAcct.makeDeposit();
break;
case 3: myAcct.dispBal();
break;
case 0: System.out.println( "Thank you, come again.");
break;
}
}
}