Here is the prompt for the first one:
Create a class to simulate an ATM machine. Create 10 accounts in an array with id 0, 1,........,9 and initial balance $100. The system should prompt 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/window should be displayed. The main window should have 4 choices.
1. Check Balance
2. Withdraw
3. Deposit
4. Exit
If exit is chosen, the system should prompt for the id again. Which means once the system starts, it will never stop.
Now I wrote a program a few chapters ago that is on the same lines. It just needs a major tweak here and there for the assignment to be fulfilled.
Could someone look at that code and maybe comment out the parts of code that is not needed, and add some comments in the appropriate places for code that is needed to complete the prompt?
import javax.swing.JOptionPane;
import java.util.Date;
public class TestAccount {
public static void main(String[] args) {
Account account = new Account(1122, 20000, 4.5);
account.setWithdraw(0);
account.setDeposite(0);
account.setTotal(0);
account.setMonthly(0);
JOptionPane.showMessageDialog(null, account.toString());
JOptionPane.showMessageDialog(null, "Good Buy");
}
}
class Account {
private int id = 0;
private double balance = 0;
private double annualInterestRate = 0;
private double withdraw = 0;
private double deposite = 0;
private double total = 0;
private double monthly = 0;
private Date date = new Date();
public Account() {
}
public Account(int id, double balance, double annualInterestRate){
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
}
public int getId(){
return this.id;
}
public void setId(int newId) {
id = newId;
}
public double getBalance() {
return this.balance;
}
public void setBalance(double newBalance) {
balance = newBalance;
}
public double getAnnualInterestRate() {
return this.annualInterestRate;
}
public void setAnnualInterestRate(double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
public java.util.Date getDate() {
return this.date;
}
public double getWithdraw() {
return this.withdraw;
}
public void setWithdraw(double newWithdraw) {
withdraw = Double.parseDouble(JOptionPane.showInputDialog(null, "Account Balance: $"
+ balance + "\n" + "\nHow much would like to withdraw?"));
}
public double getDeposite() {
return this.deposite;
}
public void setDeposite(double newDeposite) {
deposite = Double.parseDouble(JOptionPane.showInputDialog(null, "Account Balance: "
+ (balance - withdraw) + "\n" + "\nHow much would like to deposite?"));
}
public double getTotal(double balance, double deposite, double withdraw) {
return this.total;
}
public void setTotal(double newTotal) {
total = balance - withdraw + deposite;
}
public double getMonthly(double total) {
return this.monthly;
}
public void setMonthly(double newMonthly) {
monthly = total * .045 / 12;
}
public String toString() {
return "Banking Account Information\n"
+ "\nYour Customer ID # " + id
+ "\nStarting Balnce $" + balance
+ "\nAnnual Interest Rate " + annualInterestRate + "%"
+ "\nWithdraw Amount $" + withdraw
+ "\nDeposite Amount $" + deposite
+ "\nSubtotal $" + total
+ "\nMonthly Interest $"
+ Math.round(monthly * 100.0)/100.0
+ "\n" + "\n" + "As of " + date;
}
}
Thanks a lot for your help. Everyone here has been so helpful on furthering my understanding of this language. Every pointer has added as much knowledge as I receive in my class, so I tell everyone that this is my second classroom.

New Topic/Question
Reply




MultiQuote







|