SO, I have been working on this Java program that is to emulate an ATM.
I am having an issue with the program calling my functions.
The code currently does not run.
The user inputs 1,2, or 3 and the code breaks because I am assuming that the constructor is lost once the mainMenu() function runs.
Currently, Netbeans is stating that it "cannot find symbol" when it attempts to run the following:
myATM.deposit();
myATM.withdraw();
myATM.getBalance();
Here's what I have currently.
I have to have the separate functions for withdraw, deposit, and get balance.
If I move the function code into their respective menuu locations, it runs fine.
But, I have to call the functions.
Also, all of the Calendar stuff at the top is eventually going to be used to calculate interest. I have to get the program working first before I can worry about the interest stuff.
package edu.umsl.mis3806;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.lang.*;
import java.util.GregorianCalendar;
/**
*
* @author ***** */
public class ATM
{
private double balance;
private int firstdate;
private int seconddate;
private Calendar date1 = new GregorianCalendar();
private Calendar date2 = new GregorianCalendar();
private boolean dateflag = false;
private double rate; //interest rate
//public void GetInterest()
//{
//int datediff = seconddate - firstdate;
//rate = .05/365
//double ratetime = Math.pow(1+rate,datediff);
//balance = balance * ratetime;
//firstdate = seconddate;
//}
public ATM(double beginBalance) throws IOException
{
balance = beginBalance;
}
public static void main (String args[]) throws IOException
{
ATM myATM = new ATM(100);
myATM.mainMenu();
}
public void mainMenu() throws IOException
{
float input;
float amount;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println("Please select from the following: ");
System.out.println("1 to Make a Deposit: ");
System.out.println("2 to Make a Withdrawal: ");
System.out.println("3 to Check Your Balance: ");
System.out.println("4 to Exit: ");
System.out.println("Choice: ");
input = Float.parseFloat(br.readLine());
if(input == 1)
{
myATM.deposit(); //<----broken here
}
else if(input == 2)
{
myATM.withdraw(); //<------broken here
}
else if(input == 3)
{
myATM.getBalance(); //<------broken here
}
else if(input == 4)
{
System.exit(0);//exits program
}
}
public void deposit(float amount) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println("Enter the amount you wish to deposit: ");
amount = Float.parseFloat(br.readLine());
balance = (balance + amount); //deposit function
System.out.println("After your deposit your available funds are: " + (nf.format(balance)));
mainMenu();
}
public void withdraw(float amount) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println("Enter the amount you wish to withdraw: ");
amount = Float.parseFloat(br.readLine());
balance = (balance - amount); //deposit function
System.out.println("After your withdrawal your available funds are: " + (nf.format(balance)));
mainMenu();
}
public void getBalance() throws IOException
{
NumberFormat currencyFormatter;
String currencyOut;
currencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);
//currencyOut String = balance;
System.out.println("Your balance is:" + balance);
mainMenu();
}
}