Question
I need help creating a basic and simple Java program. Here is the exercise. I have included my Account class that is referred to at
I need help creating a basic and simple Java program. Here is the exercise. I have included my Account class that is referred to at the bottom, below the exercise.
Use the Account class created in Programming Exercise 9.7 to simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not stop. You will need to cntrl-c to stop your program; this is ok for this assignment. If you want your program to terminate more elegantly you can add in additional logic, but this is not required.
Please refer to textbook for sample output pg. 401.
Account.java
import java.util.Date;
public class Account {
private int id; private double balance; static private double annualInterestRate = 0; private Date dateCreated;
public Account() { dateCreated = new Date(); }
public Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); }
public int getId() { return id; }
public void setId(int id) { this.id = id;
}
public double getBalance() { return balance;
}
public void setBalance(double balance) {
this.balance = balance; }
public static double getAnnualInterestRate() { return annualInterestRate;
}
public static void setAnnualInterestRate(double annualInterestRate) { Account.annualInterestRate = annualInterestRate; }
public Date getDateCreated() { return dateCreated; }
public double getMonthlyInterestRate() { double monthlyInterestRate = getAnnualInterestRate() / 1200; return monthlyInterestRate; }
public double getMonthlyInterest() { double monthlyInterest= getBalance() * getMonthlyInterestRate(); return monthlyInterest; }
public void withdraw(double amount) { balance = getBalance() - amount;
}
public void deposit(double amount) { balance = getBalance() + amount;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started