Question
use java to design the application,
the GUI should appear as in the picture shown .

Use java language: Requirements Document A local bank intends to install a new automated teller machine (ATM) to allow users
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Transaction.java

public class Transaction {
private static int counter = 0;
private int id;
private String type;
private double amount;
  
public Transaction()
{
this.id = 0;
this.type = "";
this.amount = 0.0;
}

public Transaction(String type, double amount)
{
counter++;
this.id = counter;
this.type = type;
this.amount = amount;
}

public int getId() {
return id;
}
  
public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public double getAmount() {
return amount;
}

public void setAmount(double amount) {
this.amount = amount;
}
  
@Override
public String toString()
{
return ("Transaction Id: " + getId() + ", Type: " + getType() + ", Amount: $"
+ String.format("%.2f", getAmount()));
}
}

MyATM.java

import javax.swing.JOptionPane;

public class MyATM {
private int accountNumber, pin;
private double balance, fastCashAmount;
  
public MyATM()
{
this.accountNumber = 0;
this.pin = 0;
this.balance = 0.0;
this.fastCashAmount = 0.0;
}

public MyATM(int accountNumber, int pin, double balance, double fastCashAmount) {
this.accountNumber = accountNumber;
this.pin = pin;
this.balance = balance;
this.fastCashAmount = fastCashAmount;
}
  
public int getAccountNumber() {
return accountNumber;
}

public int getPin() {
return pin;
}

public double getFastCashAmount() {
return fastCashAmount;
}
  
public void getBalance() {
JOptionPane.showMessageDialog(null, "Your current balance is: $" + String.format("%.2f", this.balance));
}
  
public void getFastCash()
{
if(this.balance == this.fastCashAmount)
{
JOptionPane.showMessageDialog(null, "You attempted to withdraw your entire balance.\n"
+ "Please deposit an amount to proceed with this feature.");
}
else if(this.balance < this.fastCashAmount)
{
JOptionPane.showMessageDialog(null, "Transaction failed due to insufficient funds.\n"
+ "Please deposit an amount to proceed with this feature.");
}
else
{
this.balance -= this.fastCashAmount;
JOptionPane.showMessageDialog(null, "Transaction for Fast Cash of $" + this.fastCashAmount + " is successful.\n"
+ "Current balance: $" + String.format("%.2f", this.balance));
}
}
  
public void getWithdrawal(double amount)
{
if(this.balance == amount)
{
JOptionPane.showMessageDialog(null, "You attempted to withdraw your entire balance.\n"
+ "Please deposit an amount to proceed with this feature.");
}
else if(this.balance < amount)
{
JOptionPane.showMessageDialog(null, "Transaction failed due to insufficient funds.\n"
+ "Please deposit an amount to proceed with this feature.");
}
else
{
this.balance -= amount;
JOptionPane.showMessageDialog(null, "Withdrawal successful.\nCurrent balance: $"
+ String.format("%.2f", this.balance));
}
}
  
public void getDeposit(double amount)
{
this.balance += amount;
JOptionPane.showMessageDialog(null, "Deposit successful.\n"
+ "Current balance: $" + String.format("%.2f", this.balance));
}
}

ATMMachine.java (Main/Driver class)

import java.util.ArrayList;
import javax.swing.JOptionPane;

public class ATMMachine {

private static ArrayList<Integer> accNumbers = new ArrayList<>();
private static ArrayList<Integer> pins = new ArrayList<>();
private static ArrayList<MyATM> atms = new ArrayList<>();
private static ArrayList<Double> balances = new ArrayList<>();
private static ArrayList<Transaction> transactions = new ArrayList<>();

public static void main(String[] args) {
  
accNumbers.add(1234);
accNumbers.add(2341);
accNumbers.add(3412);
accNumbers.add(4123);

pins.add(234);
pins.add(341);
pins.add(412);
pins.add(123);
  
balances.add(1000.00);
balances.add(2000.00);
balances.add(300.00);
balances.add(0.00);

atms.add(new MyATM(1234, 234, balances.get(0), 200));
atms.add(new MyATM(2341, 341, balances.get(1), 350));
atms.add(new MyATM(3412, 412, balances.get(2), 490));
atms.add(new MyATM(4123, 123, balances.get(3), 580));

int wrongAccNum = 0, wrongPin = 0;

JOptionPane.showMessageDialog(null, "Welcome to the Virtual ATM Machine", "ATM Machine",
JOptionPane.INFORMATION_MESSAGE);

// prompt user to enter account number
int accountNumber = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter your account number: "));
int accNumIndex = checkAccountNumber(accountNumber);
while (accNumIndex == -1) {
wrongAccNum++;
if (wrongAccNum == 3) {
JOptionPane.showMessageDialog(null, "You've exhausted all your attempts.\n"
+ "Please contact your financial institution.");
System.exit(0);
} else {
accountNumber = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter your account number: "));
accNumIndex = checkAccountNumber(accountNumber);
}
}

// here, means account number is correct. Now prompt user for atm pin
int correctAtmPin = pins.get(accNumIndex);
int atmPin = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the PIN for your account number: "));
while (!checkATMPin(correctAtmPin, atmPin)) {
wrongPin++;
if (wrongPin == 3) {
JOptionPane.showMessageDialog(null, "You've exhausted all your attempts.\n"
+ "Please contact your financial institution.");
System.exit(0);
} else {
atmPin = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the PIN for your account number: "));
}
}

// account number and atm pin entered by user are correct
// get the particular atm object
MyATM atm = getAccount(accountNumber, correctAtmPin);
char choice = 0;

do {
choice = printMenu();

switch (choice) {
case 'a': {
atm.getBalance();
transactions.add(new Transaction("Balance Enquiry", 0));
break;
}
case 'b': {
atm.getFastCash();
transactions.add(new Transaction("Fast Cash", atm.getFastCashAmount()));
break;
}
case 'c': {
double amount = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the amount to withdraw: "));
atm.getWithdrawal(amount);
transactions.add(new Transaction("Withdraw", amount));
break;
}
case 'd': {
double amount = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the amount to deposit: "));
atm.getDeposit(amount);
transactions.add(new Transaction("Deposit", amount));
break;
}
case 'e': {
int q = JOptionPane.showConfirmDialog(null, "Thank you for visiting our ATM.\n"
+ "Would you like to print a recepit?", "Print Receipt", JOptionPane.YES_NO_OPTION);
if(q == 0)
{
// print the list of transactions
String receipt = "";
for(Transaction trans : transactions)
{
receipt += trans.toString() + "\n";
}
JOptionPane.showMessageDialog(null,
"Thank you for visiting our ATM. Your recepit:\n" + receipt + "\n");
}
System.exit(0);
}
default:
JOptionPane.showMessageDialog(null, "Invalid choice!");
}
} while (choice != 'e');
}

private static char printMenu() {
char choice = JOptionPane.showInputDialog(null, "Please choose one of the following options:\n"
+ "a. Balance Inquiry\n"
+ "b. Fast Cash\n"
+ "c. Withdrawal\n"
+ "d. Deposit\n"
+ "e. Quit\n\n"
+ "Enter your choice: ").charAt(0);

return choice;
}

private static int checkAccountNumber(int accNum) {
int index = -1;
for (int i = 0; i < accNumbers.size(); i++) {
if (accNumbers.get(i) == accNum) {
index = i;
break;
}
}
return index;
}

private static boolean checkATMPin(int correctPin, int userPin) {
return (userPin == correctPin);
}

private static MyATM getAccount(int accNum, int pin) {
boolean found = false;
int index = -1;
for (int i = 0; i < atms.size(); i++) {
if (atms.get(i).getAccountNumber() == accNum && atms.get(i).getPin() == pin) {
found = true;
index = i;
break;
}
}
if (!found) {
return null;
} else {
return atms.get(index);
}
}
}

********************************************************* SCREENSHOT *******************************************************

Input ? Please enter your account number: OK Cancel

Input х ? Please choose one of the following options: a. Balance Inquiry b. Fast Cash c. Withdrawal d. Deposit e. Quit Enter

Message х i Your current balance is: $2000.00 OK

Input X ? Enter the amount to withdraw: 780 OK Cancel

Message Х i Deposit successful. Current balance: $2420.55 OK

Print Receipt X ? Thank you for visiting our ATM. Would you like to print a recepit? Yes No

Message х i Thank you for visiting our ATM. Your recepit: Transaction Id: 1, Type: Balance Enquiry, Amount: $0.00 Transaction

Add a comment
Know the answer?
Add Answer to:
use java to design the application, the GUI should appear as in the picture shown ....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached...

    Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached the scenario in the photos. this is for programming logic and design Scenario A local bank intends to install a new automated teller machine (ATM) to allow users (i.e., bank customers) to perform basic financial transactions (see below figure). Each user can have only one account at the bank. ATM users should be able to do the following; View their account balance. Withdraw cash...

  • 1- TigerOne Bank is a local bank that intends to install a new automated teller machine...

    1- TigerOne Bank is a local bank that intends to install a new automated teller machine (ATM) to allow its customers to perform basic financial transactions. Using the ATM machine users should be able to view their account balance, withdraw cash and deposit funds. The bank wants you to develop the software application that will be installed on the new ATM machines. The following are the requirements for the application:  Users are uniquely identified by an account number and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT