My next quandary is how to get the input for the withdraw and deposit?
Updated code...
import javax.swing.JOptionPane;
import java.util.Date;
public class TestATM {
public static void main(String[] args) {
//Creates 10 accounts
Account[] accounts = new Account[10];
for (int i = 0; i < accounts.length; i++) {
accounts[i] = new Account();
}
while(true) {
boolean using = true;
int idInput = Integer.parseInt(JOptionPane.showInputDialog("Enter your account ID"));
int index = -1; //holder position for the Account index
for(int i = 0; i < accounts.length; i++) {
if(accounts[i].getId() == idInput) {
index = i; //we have the index;
i = accounts.length;
}
}
if(index != -1) {
while(using) {
//display menu and do everything in here. If exit is selected set using to false and it will go back to the ID input
}
}
else {
JOptionPane.showMessageDialog(null, "invalid ID");
}
JOptionPane.showMessageDialog(null,
"Your balance is: $" + accounts[0].getBalance());
}
}
}
class Account {
private int id = 0;
private double balance = 100;
private double withdraw = 0;
private double deposit = 0;
private double amount = 0;
private Date date = new Date();
public Account() {
}
public Account(int id, double balance){
this.id = id;
this.balance = balance;
}
public int getId(){
return this.id;
}
public void setId(int newId) {
id = newId;
}
public double getBalance() {
return this.balance;
}
public java.util.Date getDate() {
return this.date;
}
public double getWithdraw() {
return this.withdraw;
}
public void withdraw(double amount) {
balance -= amount;
}
public double getDeposit() {
return this.deposit;
}
public void deposit(double amount) {
balance += amount;
}
public String toString() {
return "Banking Account Information\n"
+ "\nStarting Balnce $" + balance
+ "\nYour Customer ID # " + id
+ "\nWithdraw Amount $" + withdraw
+ "\nDeposite Amount $" + deposit
+ "\n" + "\n" + date;
}
}

New Topic/Question
Reply





MultiQuote







|