QuestionQuestion

Question 1. Implement a queue using an array. Implement the following methods in class Queue: enqueue(), dequeue(), peek(), and empty(). Your queue should store references to class Object.

Question 2. Use the queue you have implemented in Question 1 to write code for this question. You are asked to design and implement a simulated Automated Teller Machine (ATM). The machine will process several transactions per day. The transactions are processed in a first-in-first-out order. A Transaction has the following fields: a person (who made the transaction), a date, a time of the day, a type (debit, credit or transfer of money) and an amount (debited, credited or transferred). A person has a name, a client number, a linked lists of accounts. An account has an account number, a type (checking or savings), a balance.

People line up to use the ATM and each person is allowed 1 or more transactions. When a person wants to use the machine, he/she is prompted for an identification number and a password. A list of all identification numbers along with their passwords is stored in a text file. The program should validate the id number and the password according to the file. When the user is allowed access to the machine, he/she is presented with the following choices:

1. Withdraw money
2. Deposit money
3. Transfer of Money
4. Display account info
5. Exit
- - - - - - - - - - - -
Input your choice:

-The Withdraw money option allows the user to withdraw an amount from one of his/her accounts.
-The Deposit money option allows the user to deposit money into one of his/her accounts.
-The Transfer of money option allows the user to transfer money between two accounts.
-The Display account info option prints to the screen the balance of the account that the user has.
-The Exit option lets the machine display the welcoming message again asking the user to enter identification number and password.
-Transactions that occur before 6:00 pm are processed the same day. Transactions that occur after 6:00 pm are processed the next working day (Sundays are off). Hence, at the end of the day, some transactions might still be in the queue. Before exiting the program, you should allow the user to see which transactions are still on the queue.

The information regarding the users and their accounts is initially stored in a text file. When the program first starts, it reads the information from the file and creates the appropriate objects.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package atmsimulator;

import java.util.LinkedList;
import java.time.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class ATMSimulator {
   
    enum AccountType {CHECKING, SAVING};
    enum TransactionType {DEBIT, CREDIT, TRANSFER};
   
    public static class Account
    {
       int accountNumber;
       AccountType accountType;
       float balance;
    }
   
    public static class Person
    {
       String name;
       int clientNumber;
       LinkedList<Account> accounts;
       int ID;
       String password;      
    }
   
    public static class Transaction
    {
       Person person;
       LocalDate date;
       LocalTime time;
       TransactionType type;
       float amount;
       Account account;
    }
   
    public static void printAccounts(Person client)
    {
       for (int j = 0; j < client.accounts.size(); j++)
       {
            System.out.print(j + 1);
            System.out.println(". ");
            System.out.print("Account number: ");
            System.out.println(client.accounts.get(j).accountNumber);
            System.out.print("Account type: ");
            System.out.println(client.accounts.get(j).accountType.toString());
            System.out.print("Balance: ");
            System.out.println(client.accounts.get(j).balance);
            System.out.println();
       }      
    }
   
    public static int getAccountNumber(Person client)
    {
       int c = 0;
       Scanner scc = new Scanner(System.in);
       do
       {
            printAccounts(client);
            System.out.print("Choose account: ");
            c = Integer.parseInt(scc.nextLine());
       } while ((c < 0) || (c > client.accounts.size()));
       return c - 1;
    }
   
    public static TransactionType getTransactionType()
    {
       Scanner sc = new Scanner(System.in);
       int c;
       TransactionType tt;
       do
       {
            System.out.println();
            System.out.println("1. Debit");
            System.out.println("2. Credit");
            System.out.println();
            System.out.print("Enter 1-2: ");
            c = Integer.parseInt(sc.nextLine());
       } while ((c < 1) || (c > 2));
       if (c == 1)
       {
            tt = TransactionType.DEBIT;
       }
       else
       {
            tt = TransactionType.CREDIT;
       }
       return tt;
    }
   
    public static boolean confirmation(String str)
    {
       boolean conf = false;
       Scanner sc = new Scanner(System.in);
       System.out.println();
       System.out.println(str + "[y]: ");
       if (sc.nextLine().equals("y"))
       {
            conf = true;
       }
       return conf;
    }
   
    public static void printTransaction(Transaction transaction)
    {
       System.out.println(transaction.person.name);
       System.out.println(transaction.person.clientNumber);
       System.out.println(transaction.date.toString());
       System.out.println(transaction.time.toString());
       System.out.println(transaction.type.toString());
       System.out.println(transaction.amount);
       System.out.println();
    }
   
    public static void printTransactions(Queue transactions, Person client)
    {
       Queue tmp = transactions;
       while (!tmp.empty())
       {
            if (client == null)
            {
                printTransaction((Transaction)transactions.dequeue());
            }
            else
            {
                Transaction transaction = (Transaction)transactions.dequeue();
                if (transaction.person.clientNumber == client.clientNumber)
                {
                   printTransaction(transaction);
                }
            }
               
       }
    }
   
    public static void doTransactions(Queue transactions)
    {
       Transaction transaction = (Transaction)transactions.peek();
       while ( (!transactions.empty()) &&
                (!(LocalDate.now().getDayOfWeek().equals(DayOfWeek.SUNDAY))) &&
                ((transaction.date.isBefore(LocalDate.now())) ||
                (transaction.date.isEqual(LocalDate.now()) && (transaction.time.isBefore(LocalTime.of(18, 0)))) ))
       {
            Person client = transaction.person;
            int i = 0;
            while (!client.accounts.get(i).equals(transaction.account))
            {
                i++;
            }
            client.accounts.get(i).balance += transaction.amount;
            transactions.dequeue();
            transaction = (Transaction)transactions.peek();
       }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) throws FileNotFoundException {
       // TODO code application logic here
       File file = new File("Clients.txt");
       Scanner sc = new Scanner(file);
       LinkedList<Person> persons = new LinkedList();
       Queue transactions = new Queue(20);
       while (sc.hasNextLine())
       {
            Person person = new Person();
            person.name = sc.nextLine();
            person.clientNumber = Integer.parseInt(sc.nextLine());
            person.ID = Integer.parseInt(sc.nextLine());
            person.password = sc.nextLine();
            String s = sc.nextLine();
            person.accounts = new LinkedList();
            while (!s.equals(""))
            {
                Account account = new Account();
                account.accountNumber = Integer.parseInt(s);
                s = sc.nextLine();
                if (s.equals("S"))
                {
                   account.accountType = AccountType.SAVING;
                }
                else
                {
                   account.accountType = AccountType.CHECKING;
                }
                account.balance = Float.parseFloat(sc.nextLine());
                person.accounts.add(account);
                if (sc.hasNextLine())
                {
                   s = sc.nextLine();
                }
                else
                {
                   s = "";
                }
            }
            persons.add(person);
       }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$25.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats